home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / embedded / mcu11 / mcx11v15.arc / MANUAL.DOC < prev    next >
Text File  |  1990-04-11  |  129KB  |  3,829 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.             
  9.             
  10.             
  11.             
  12.             
  13.             
  14.             
  15.                                        MCX11
  16.                                           
  17.                              MicroController eXecutive
  18.                                       for the
  19.                                  Motorola MC68HC11
  20.                                           
  21.                                     Version 1.3
  22.             
  23.             
  24.             
  25.             
  26.                                          by
  27.             
  28.                              A.T. Barrett & Associates
  29.                                  11501 Chimney Rock
  30.                                 Houston, Texas 77035
  31.                                    (713)728-9688
  32.             
  33.             
  34.                                     April 1990
  35.             
  36.             
  37.                                   Support Contact:
  38.                                           
  39.                                      Mike Wood
  40.                                      M/S OE319
  41.                                    Motorola, Inc.
  42.                            6501 William Cannon Drive West
  43.                                 Austin, Texas 78735
  44.                                    (512)891-2717
  45.             
  46.             
  47.             
  48.             Neither Motorola,  Inc. nor  A.T. Barrett & Associates makes
  49.             any warranty,  expressed or  implied, with  regard  to  this
  50.             material including  but not  limited to  merchantability  or
  51.             fitness for  a given  purpose.    The  information  in  this
  52.             document is  subject to  change without  notice and  neither
  53.             Motorola, Inc.  or A.T.  Barrett &  Associates  assumes  any
  54.             responsibility for  any errors which may appear herein.  Nor
  55.             shall Motorola,  Inc. or  A.T. Barrett & Associates bear any
  56.             liability  for   use   of   this   material   with   respect
  57.             compensatory,   special,   incidental,   consequential,   or
  58.             exemplary damages.
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.                   MCX11 - MicroController eXecutive for the 68HC11
  71.                                           
  72.                                           
  73.                                   TABLE OF CONTENTS
  74.                                                       
  75.             Section 1  Introduction                               Page
  76.             
  77.             1.1  Background and Features........................... 1-1
  78.             1.2  MCX11 as a Software Component..................... 1-1
  79.             1.3  Target Environment................................ 1-2
  80.             1.4  Development Environment........................... 1-2
  81.             1.5  Manual Format..................................... 1-2
  82.             
  83.             Section 2  MCX11 Functional Overview
  84.             
  85.             2.1  What Is MCX11..................................... 2-1
  86.             2.2  Tasks............................................. 2-2
  87.             2.3  Multitasking...................................... 2-2
  88.             2.4  Priority and Scheduling........................... 2-2
  89.             2.5  Intertask Communication and Synchronization....... 2-3
  90.             2.6  Time based Functions.............................. 2-4
  91.             2.7  Interrupt Service................................. 2-4
  92.             
  93.             Section 3  MCX11 Control & Data Structures
  94.             
  95.             3.1 Tasks.............................................. 3-1
  96.             3.1.1 Task Identifier & Priority....................... 3-1
  97.             3.1.2 Task State Table................................. 3-2
  98.             3.1.3 Stack............................................ 3-3
  99.             3.2  Semaphores........................................ 3-3
  100.             3.3  Messages and Mailboxes............................ 3-5
  101.             3.4  Queues............................................ 3-7
  102.             3.5 Timers............................................. 3-8
  103.             
  104.             Section 4  Executive Service Requests (ESRs)
  105.             
  106.             4.1  Purpose........................................... 4-1
  107.             4.2  Semaphore ESRs.................................... 4-1
  108.             4.3  Message ESRs...................................... 4-2
  109.             4.4  Queue ESRs........................................ 4-2
  110.             4.5  Task Control ESRs................................. 4-2
  111.             4.6  Time Based ESRs................................... 4-2
  112.             
  113.             Section 5  Alphabetical Listing of ESRs
  114.             
  115.             5.1  .delay.  -  Delay a Task for a Period of Time..... 5-2
  116.             5.2  .dequeue.  -  Get an Entry from a FIFO Queue...... 5-4
  117.             5.3  .enqueue.  -  Insert Data into FIFO Queue......... 5-6
  118.             5.4  .execute.  -  Execute a Task...................... 5-9
  119.             5.5  .pend.  -  Force a Semaphore to a PENDING State.. 5-11
  120.             5.6  .purge.  -  Purge a Task's Timers................ 5-12
  121.             5.7  .receive.  -  Receive a Message.................. 5-14
  122.             5.8  .resume.  -  Resume a Task....................... 5-16
  123.             5.9  .send.  -  Send a Message to a Task.............. 5-17
  124.             5.10  .sendw.  -  Send a Message and Wait............. 5-19
  125.             5.11  .signal.  -  Signal a Semaphore................. 5-20
  126.  
  127.  
  128.  
  129.                                         Page i
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.                   MCX11 - MicroController eXecutive for the 68HC11
  137.                                           
  138.                                           
  139.                                   TABLE OF CONTENTS
  140.                                                       5.12  .suspend.  -  Suspend a Task.................... 5-22
  141.             5.13  .terminate.  -  Terminate a Task................ 5-23
  142.             5.14  .timer.  -  Start a Timer....................... 5-24
  143.             5.15  .wait.  -  Wait on Semaphore.................... 5-26
  144.             
  145.             Section 6  System Configuration
  146.             
  147.             6.1  System Configuration Concepts..................... 6-1
  148.             6.2  MCX11 System Table Memory Requirements............ 6-1
  149.             
  150.             Section 7  Device Driver & Interrupts
  151.             
  152.             7.1  Driver Concepts................................... 7-1
  153.             7.2  Interrupt Service................................. 7-1
  154.             7.2.1 Interrupt Processing Variables................... 7-2
  155.             7.2.2 Interrupt Processing Code........................ 7-4
  156.             
  157.             Section 8  Advanced Topics
  158.             
  159.             8.1  Other topics...................................... 8-1
  160.             
  161.             Appendix A  MCX11 Distributed Source Files............. A-1
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                        Page ii
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.                   MCX11 - MicroController eXecutive for the 68HC11
  203.  
  204.  
  205.  
  206.                                      SECTION 1
  207.                                           
  208.                                     INTRODUCTION
  209.                                           
  210.                                           
  211.             1.1  BACKGROUND AND FEATURES
  212.             
  213.             MCX11, the MicroController eXecutive for the MC68HC11, is an
  214.             efficient  software   framework   for   embedded   real-time
  215.             applications using  the Motorola  MC68HC11  microcontroller.
  216.             Motorola, Inc.  makes MCX11 available free of charge via the
  217.             Freeware Bulletin  Board System.   MCX11  is written  in the
  218.             AS11 assembly  language  which  is  also  available  on  the
  219.             Motorola Freeware BBS (512/891-3733).
  220.             
  221.             MCX11 provides  many features  which are designed to support
  222.             real-time applications.  These features include:
  223.             
  224.                 -     Multitasking for up to 126 tasks
  225.                 -     Pre-emptive task scheduling by priority
  226.                 -     Intertask communication and synchronization via
  227.                        semaphores, messages, and queues.
  228.                 -     Support for timed operations
  229.                 -     Fast context switch
  230.                 -     Very small RAM and ROM requirements
  231.                 -     Fifteen Executive Service Request functions
  232.             
  233.             
  234.             1.2  MCX11 AS A SOFTWARE COMPONENT
  235.             
  236.             MCX11 is  furnished in  AS11 source form and is downloadable
  237.             via  a   modem  connection  to  the  Freeware  BBS.  In  its
  238.             distribution  form,  it  is  not  executable.    It  may  be
  239.             assembled separately  or with  the application  programs and
  240.             any device  drivers peculiar  to the application.  MCX11 may
  241.             be treated as any other software library.  The user need not
  242.             know how  MCX11 performs  its functions internally.  Rather,
  243.             the user  need only  know what  functions of MCX11 to use to
  244.             achieve a  desired result.   Thus, MCX11 becomes much like a
  245.             large scale  integrated circuit  component in  the hardware.
  246.             Knowledge of what inputs produce what outputs is all that is
  247.             needed to  use  the  "chip"  successfully.  Unlike  a  chip,
  248.             however, MCX11  users are  provided with  the source code to
  249.             the kernel  so that  they can exercise complete control over
  250.             their applications.  With the  source code,  users may  even
  251.             wish to extend the functionality of MCX11 by the addition of
  252.             new services.
  253.             
  254.             This manual  is not meant as a tutorial on real-time kernels
  255.             in general.  It is  intended to  explain  the  "inputs"  and
  256.             "outputs" of  MCX11 as  a software  component of  the user's
  257.             application.  In  an  effort  to  assist  the  user  in  the
  258.  
  259.  
  260.  
  261.             Copyright (c) 1989         Page 1 - 1          Motorola, Inc.
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.                   MCX11 - MicroController eXecutive for the 68HC11
  269.  
  270.  
  271.  
  272.             successful employment  of MCX11,  this manual will cover the
  273.             following subjects:
  274.             
  275.                 -     basic concepts of MCX11 design
  276.                 -     interfaces to the MCX11 services
  277.                 -     system generation procedure
  278.                 -     assembly procedure for MCX11 and application
  279.                        source files
  280.                 -     procedure for merging MCX11 with the application
  281.                        object files
  282.             
  283.             1.3  TARGET ENVIRONMENT
  284.             
  285.             MCX11 is  designed to operate in an embedded processor, that
  286.             is, one whose functions are fixed within the application. No
  287.             assumptions are  made about  the configuration of the target
  288.             system.   It is the responsibility of the user to define the
  289.             target environment  and to insure that all necessary devices
  290.             have program support. No distinction is made between Single-
  291.             Chip Operating  mode or  Expanded Multiplexed Operating mode
  292.             in the design of MCX11. If there are special requirements in
  293.             the application for functions related to a certain operating
  294.             mode, it will be the responsibility of the user to add them.
  295.             
  296.             
  297.             1.4  DEVELOPMENT ENVIRONMENT
  298.             
  299.             MCX11 development  requires a  computer compatible  with the
  300.             IBM PC and having at least 256K bytes of RAM, 1 floppy disk,
  301.             a keyboard, and a video monitor, an RS-232 compatible serial
  302.             I/O port, a Centronics compatible parallel printer port, and
  303.             a printer (preferably one which is Epson compatible). A hard
  304.             disk  is   very  desirable   for  development   work.   This
  305.             configuration is  needed to run the AS11 cross assembler and
  306.             serve as a debug terminal to the target assuming MC68HC11EVM
  307.             Evaluation Module is being used. Consult the EVM User Manual
  308.             for specifics  on connection tp PC. Recommended software for
  309.             the  development  environment  besides  MS-DOS  includes  an
  310.             editor,  and   the  Kermit  communications  program  (public
  311.             domain).
  312.             
  313.             
  314.             1.5  MANUAL FORMAT
  315.             
  316.             Section 1 of this manual is simply an overview of MCX11.
  317.             
  318.             Section 2 gives the functional overview of MCX11.
  319.             
  320.             Section 3  details  the  organization  and  content  of  the
  321.             various MCX11 control and data structures.
  322.             
  323.  
  324.  
  325.  
  326.  
  327.             Copyright (c) 1989         Page 1 - 2          Motorola, Inc.
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.                   MCX11 - MicroController eXecutive for the 68HC11
  335.  
  336.  
  337.  
  338.             Section 4  gives a  description  of  the  Executive  Service
  339.             Requests (ESRs)  provided by  MCX11, subdivided  into  their
  340.             classes.
  341.             
  342.             Section 5  gives an  alphabetical presentation  of all MCX11
  343.             Executive Service Requests.
  344.             
  345.             Section 6  deals with  the configuration  and generation  of
  346.             MCX11 systems.
  347.             
  348.             Section 7  discusses device  drivers and  interuupt  service
  349.             routines.
  350.             
  351.             Section 8  presents technical information on advanced topics
  352.             related to the use of MCX11.
  353.             
  354.             Appendices  round   out  the  specifics  of  necessary  user
  355.             knowledge.
  356.             
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.             Copyright (c) 1989         Page 1 - 3          Motorola, Inc.
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.                   MCX11 - MicroController eXecutive for the 68HC11
  401.  
  402.  
  403.  
  404.                                      SECTION 2
  405.                                           
  406.                              MCX11 FUNCTIONAL OVERVIEW
  407.                                           
  408.             
  409.             2.1  WHAT IS MCX11
  410.             
  411.             A real-time  executive provides  a software framework within
  412.             which different  processes can  operate and  gain access  to
  413.             various system resources.  Real-time systems usually consist
  414.             of several  processes, or  tasks, which need to have control
  415.             of  the  system  resources  at  varying  times  due  to  the
  416.             occurrence of  external events.  These tasks  are at various
  417.             times  competing   for  system  resources  such  as  memory,
  418.             execution time, or peripheral devices. They range from being
  419.             compute bound  to I/O  bound. Tasks which are I/O or compute
  420.             bound   cannot be allowed to monopolize a system resource if
  421.             a more important function requires the same resource.  There
  422.             must be  a way  of interrupting the operation of the task of
  423.             lesser importance  and granting  the needed  resource to the
  424.             more important task.
  425.             
  426.             A multitasking   real-time  executive  promotes  an  orderly
  427.             transfer of  control from  one task  to  another  such  that
  428.             efficient usage  of the  computer's resources  is  achieved.
  429.             Orderly transfers  require that  the executive keep track of
  430.             the needed resources and the execution state of each task so
  431.             that they  can be  granted to  each task in a timely manner.
  432.             The key  word there is timely. A real-time system which does
  433.             not perform  a required  operation at  the correct  time has
  434.             failed. That  failure can have consequences which range from
  435.             the benign  to the catastrophic. Response time to a need for
  436.             executive services  and the  execution time of such services
  437.             must be  sufficiently fast  enough  so  that  no  need  goes
  438.             undetected.
  439.             
  440.             One way  to  achieve  timeliness  is  the  assignment  of  a
  441.             priority to  each task.  The priority of a task is then used
  442.             to determine  its place  within the sequence of execution of
  443.             all tasks.  Tasks of  low priority  may have their execution
  444.             pre-empted by  a task  of higher priority so that the latter
  445.             can perform some time critical function.
  446.             
  447.             An event  can be any stimulus which requires a reaction from
  448.             the executive  or a task. Examples of an event would include
  449.             a timer  interrupt, an alarm condition, or a keyboard input.
  450.             Events  may   originate  externally   to  the  processor  or
  451.             internally from  within the  software.  An  executive  which
  452.             responds to  these events  as  the  stimuli  for  allocating
  453.             resources is  said to  be event  driven. If response time to
  454.             any event   occurs  within a  period of  time which  can  be
  455.  
  456.  
  457.  
  458.  
  459.             Copyright (c) 1989         Page 2 - 1          Motorola, Inc.
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.                   MCX11 - MicroController eXecutive for the 68HC11
  467.  
  468.  
  469.  
  470.             accurately defined and guaranteed, the executive can be said
  471.             to be deterministic.
  472.             
  473.             By  these  definitions,  MCX11  is  a  deterministic,  event
  474.             driven, multitasking, real-time executive.
  475.             
  476.             
  477.             2.2  TASKS
  478.             
  479.             In MCX11, a task is a program module which exists to perform
  480.             a  defined  function  or  set  of  functions.    A  task  is
  481.             independent of  other tasks  but may establish relationships
  482.             with other tasks.  These relationships may exist in the form
  483.             of data  structures, input/output,  or other  constructs.  A
  484.             task executes when the MCX11 task dispatcher determines that
  485.             the resources  required by  the task are available.  Once it
  486.             begins running,  the task has control of all of the system's
  487.             resources.   But as  there are  other tasks in the system, a
  488.             running task  cannot  be  allowed  to  control  all  of  the
  489.             resources all  of the time.  Thus, MCX11 employs the concept
  490.             of multitasking.
  491.             
  492.             
  493.             2.3  MULTITASKING
  494.             
  495.             Multitasking appears  to  give  the  computer  the  apparent
  496.             ability to  be performing  multiple operations concurrently.
  497.             Obviously, the  computer cannot  be doing two or more things
  498.             at once  as it  is a  sequential machine.  However, with the
  499.             functions of the system segregated into different tasks, the
  500.             effect of  concurrency can  be achieved.   In  multitasking,
  501.             each task  once  given  operating  control  either  runs  to
  502.             completion, or to a point where it must wait for an event to
  503.             occur, for  a needed  resource to become available, or until
  504.             it is  interrupted.   Efficient use  of the  computer can be
  505.             obtained by  using the  time a task might otherwise wait for
  506.             an event to occur to run another task.
  507.             
  508.             This switching  from one  task to another forms the basis of
  509.             multitasking.  The result is the appearance of several tasks
  510.             being executed simultaneously.
  511.             
  512.             
  513.             2.4  PRIORITY AND SCHEDULING
  514.             
  515.             When several  tasks can  be competing  for the  resource  of
  516.             execution time,  the problem is to determine how to grant it
  517.             so that  each gets  access to  the system in time to perform
  518.             its function.  The solution  is to assign a priority to each
  519.             task indicative of its relative importance to other tasks in
  520.             the system.   MCX11 uses a fixed priority scheme in which up
  521.             to 126  tasks may  be defined.   Tasks  which have a need to
  522.  
  523.  
  524.  
  525.             Copyright (c) 1989         Page 2 - 2          Motorola, Inc.
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.                   MCX11 - MicroController eXecutive for the 68HC11
  533.  
  534.  
  535.  
  536.             respond rapidly  to events  are  assigned  high  priorities.
  537.             Those which perform functions that are not time critical are
  538.             assigned lower priorities.
  539.             
  540.             It is  the priority of each task that determines where it is
  541.             to run  in the  hierarchy of  tasks.   When a  task may  run
  542.             depends  on  what  is  happening  to  the  tasks  of  higher
  543.             priority.   Tasks are  granted execution  time in  a  strict
  544.             descending order  of priority.   While executing, a task may
  545.             be interrupted  by an  event which  causes a  task of higher
  546.             priority to be runnable.  The lower  priority task is placed
  547.             into a  temporary state  of suspension and execution control
  548.             is granted to the higher priority task.  Eventually, control
  549.             is returned to the interrupted task and it is resumed at the
  550.             point of  its interruption.   Thus,  when any  task is given
  551.             execution control,  no higher  priority task  can  be  in  a
  552.             runnable state.  This is a most important point to remember.
  553.             When all  tasks are  in  an  unrunnable  state,  control  is
  554.             granted to the null task.
  555.             
  556.             The null  task is  a do-nothing task which allows the system
  557.             to run in an idle mode while waiting for an event which will
  558.             resume or  start a  higher priority  task.  The null task is
  559.             always the  lowest priority task in the system and is always
  560.             runnable. It is an integral part of the kernel.
  561.             
  562.             
  563.             2.5  INTERTASK COMMUNICATION AND SYNCHRONIZATION
  564.             
  565.             MCX11 provides  an environment whereby two or more tasks can
  566.             communicate with one another.  The three major ways in which
  567.             this  is  done  are  through  the  mechanisms  of  semaphore
  568.             signalling, message  transmission, and  queues.  A semaphore
  569.             is actually  a flag  which contains  information  about  the
  570.             state of  the associated event.  Any event which is used for
  571.             task synchronization  will be  associated with  a particular
  572.             semaphore.   The occurrence  of  a  specific  event  can  be
  573.             signalled by manipulating the semaphore associated with that
  574.             event.
  575.             
  576.             Message transmission  involves the  logical transfer of data
  577.             packets from  one task  to another.   These data packets are
  578.             called "messages".   Messages  are sent  from one  task  and
  579.             placed in  the "mailbox"  of the receiving task in the order
  580.             of the  priorities of  the senders.   Messages may be of any
  581.             format recognizable  by the sender and receiver and data may
  582.             be passed  in either direction.  That is, it is possible for
  583.             two tasks to alternate the roles of sender and receiver.
  584.             
  585.             A third  technique whereby  two tasks  can  communicate  and
  586.             synchronize is  via  a  first-in-first-out  (FIFO)  queueing
  587.             mechanism.   The queueing  techniques used  by MCX11 involve
  588.  
  589.  
  590.  
  591.             Copyright (c) 1989         Page 2 - 3          Motorola, Inc.
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.                   MCX11 - MicroController eXecutive for the 68HC11
  599.  
  600.  
  601.  
  602.             the physical  transfer (copying)  of data  packets from  one
  603.             task to  another.   Task  synchronization  due  to  queueing
  604.             operations is automatically performed by MCX11.
  605.             
  606.             
  607.             2.6  TIME BASED FUNCTIONS
  608.             
  609.             An MCX11  system is  configured with an interval timer using
  610.             the Real  Time Interrupt (RTI) clock as a peripheral device.
  611.             The timer  permits  task  control  on  a  timed  basis.    A
  612.             generalized scheme  using  one-shot  and  cyclic  timers  in
  613.             conjunction with  semaphores is provided.  MCX11 efficiently
  614.             manages multiple  timers using  an ordered  linked  list  of
  615.             pending timer  events. A timer for an event is inserted into
  616.             the  linked   list  in   accordance  with  its  duration.  A
  617.             differential technique  is employed  so that  the timer with
  618.             the shortest  time to expiration is at the head of the list.
  619.             Timed  events  may  even  be  co-terminous.  Directives  for
  620.             scheduling and  cancelling timed events are an integral part
  621.             of the executive.
  622.             
  623.             
  624.             2.7  INTERRUPT SERVICE
  625.             
  626.             Support  for  a  generalized  interrupt  service  scheme  is
  627.             provided within  the MCX11  kernel. The   Interrupt  Service
  628.             Routine (ISR)  code, however,  is provided  by the User. The
  629.             rules for  writing interrupt  service routines that function
  630.             with  MCX11   are  quite   simple  and  require  only  minor
  631.             housekeeping  chores.   MCX11  also   provides  the   common
  632.             Interrupt Service  Exit function.  This logic is used by all
  633.             interrupts to  determine if  a context switch is in order as
  634.             the result  of the interrupt. If no task switch is required,
  635.             the  interrupted  task  is  resumed  at  the  point  of  the
  636.             interrupt. If,  however, a  task switch  is  in  order,  the
  637.             interrupted task's  context is saved, the new task's context
  638.             is loaded and control is given to it.
  639.             
  640.             
  641.  
  642.  
  643.  
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.             Copyright (c) 1989         Page 2 - 4          Motorola, Inc.
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.                   MCX11 - MicroController eXecutive for the 68HC11
  665.  
  666.  
  667.  
  668.                                      SECTION 3
  669.                                           
  670.                           MCX11 CONTROL & DATA STRUCTURES
  671.                                           
  672.             
  673.             In order  to understand  how MCX11  works and  how to  build
  674.             real-time application  systems around it, it is necessary to
  675.             understand how its various control and data structures work.
  676.             This  section   describes   these   structures   and   their
  677.             interrelationships. The descriptions will include:
  678.             
  679.                  -    tasks
  680.                  -    semaphores
  681.                  -    messages and mailboxes
  682.                  -    queues
  683.                  -    timers
  684.             
  685.             The MCX11  executive services  which deal with these classes
  686.             of control  and data  structures  will  be  presented  in  a
  687.             subsequent section.
  688.             
  689.             
  690.             3.1 TASKS
  691.             
  692.             In a real-time application using MCX11, the functions of the
  693.             system are  assigned to  various tasks. MCX11 supports up to
  694.             126 tasks in a single system. The nature of each task is, of
  695.             course, application dependent and left to the imagination of
  696.             the system designer. However, there are attributes which all
  697.             tasks share. These include:
  698.             
  699.                  -    a task identifier
  700.                  -    a priority
  701.                  -    a task state table
  702.                  -    a stack
  703.                  -    a mailbox
  704.                  -    an entry point
  705.             
  706.             3.1.1 Task Identifier & Priority
  707.             
  708.             Each task is identified by a numerical identifier which is a
  709.             number from  1 - 126. The task identifier, or number, serves
  710.             as a  reference  during  executive  operations.  Task  1  is
  711.             executed before task 2 which is executed prior to task 3 and
  712.             so on.  Thus, the  task number  is inversely  related to the
  713.             task's execution  priority. The  lower the  task number, the
  714.             higher the  priority. MCX11  uses this  fixed task numbering
  715.             scheme because  it is low in overhead and quite adequate for
  716.             most applications.  The task  number permits a direct access
  717.             to the  task's state table without the need for linked lists
  718.             or other commonly used technique.
  719.             
  720.  
  721.  
  722.  
  723.            Copyright (c) 1989          Page 3 - 1          Motorola, Inc.
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.                   MCX11 - MicroController eXecutive for the 68HC11
  731.  
  732.  
  733.  
  734.             3.1.2 Task State Table
  735.             
  736.             The state  table is  commonly referred  to as a Task Control
  737.             Block (TCB).  A TCB  in MCX11  is contained  in two separate
  738.             sections in  order to  minimize the  use of system RAM. Only
  739.             those data about the execution state of the task are kept in
  740.             RAM. Static  information about the task is kept in ROM. Both
  741.             sets of  this TCB information are kept in arrays which allow
  742.             direct access  to the  data based  on the  task number. This
  743.             makes for very quick access without the commonly wasted time
  744.             of searching a linked list.
  745.             
  746.             The RAM portion of the TCB contains only volatile data about
  747.             the task and includes the following:
  748.             
  749.                  -    the execution state
  750.                  -    the stack pointer
  751.                  -    the first link in the task's mailbox
  752.             
  753.             Whenever the  MCX11 dispatcher  is looking  for  a  task  to
  754.             execute, it  examines the execution state variable to see if
  755.             the  task  is  runnable  or  not.  The  execution  state  is
  756.             contained in a single byte and a value of $00 indicates that
  757.             the task  is runnable.  Any other  content in the task state
  758.             and the task is blocked from running.
  759.             
  760.             The stack  pointer contains  the address of the current top-
  761.             of-stack.
  762.             
  763.             The first link in the task's mailbox contains the address of
  764.             the highest  priority message  waiting to be received by the
  765.             task. If no message is waiting, the pointer contains zero.
  766.             
  767.             The ROM part of the TCB contains:
  768.             
  769.                  -    the initial execution state
  770.                  -    the entry point
  771.                  -    the base address of the stack
  772.                  -    the address of the RAM part of the TCB
  773.             
  774.             The initial  execution state  is  specified  by  the  system
  775.             designer at  the time  of system configuration. This becomes
  776.             the initial  content of the execution state. By specifying a
  777.             value of  zero, the  task will be executed immediately after
  778.             initialization   in    accordance   with    its    priority.
  779.             Specification of a non-zero value will prevent the task from
  780.             automatically starting execution after initialization.
  781.             
  782.             The entry  point is  the address  where the task is to begin
  783.             execution.
  784.             
  785.  
  786.  
  787.  
  788.  
  789.            Copyright (c) 1989          Page 3 - 2          Motorola, Inc.
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.                   MCX11 - MicroController eXecutive for the 68HC11
  797.  
  798.  
  799.  
  800.             The base  address of  the stack  identifies that location in
  801.             RAM where the task's stack begins.
  802.             
  803.             The address of the RAM part of the TCB table is included for
  804.             completeness and  is sometimes  used to save time in setting
  805.             up the address of the RAM TCB area.
  806.             
  807.             3.1.3 Stack
  808.             
  809.             Each task must have a stack on which the context of the task
  810.             is saved  during those periods when the task is not actually
  811.             executing. The  base address  of the  stack is stored in the
  812.             ROM portion  of the  TCB. The  stack extends  from the  base
  813.             address downward  in memory, i.e. towards address $0000, for
  814.             a number  of bytes specified by the given stack size for the
  815.             task. The  size of  each task's  stack is  dependent on many
  816.             things such  as the  maximum  depth  of  nested  subroutines
  817.             calls, the  maximum  amount  of  working  space  needed  for
  818.             temporary variables,  and the  size of any stack frames used
  819.             by the  task. At  minimum, the  size of the stack must allow
  820.             for the  storage of  a complete  context which requires nine
  821.             (9) bytes.  If XIRQ  is to  be used  in the design, an extra
  822.             nine (9) bytes must be allocated to each task's stack due to
  823.             the possibility of stacking an IRQ followed by an XIRQ. This
  824.             is possible  because the  XIRQ  cannot  be  masked  and  can
  825.             interrupt an IRQ interrupt service routine at any point.
  826.             
  827.             In addition to the stacks needed by the tasks, there is also
  828.             the need  for a stack for MCX11. This system stack must have
  829.             sufficient space  to handle the maximum number of interrupts
  830.             possible  at  any  given  time,  less  one  interrupt.  Each
  831.             interrupt requires  nine bytes. MCX11 functions have a worst
  832.             case stack  requirement of  seven (7)  bytes  not  including
  833.             those bytes required for the system stack.
  834.             
  835.             The sum  of all  of the  stack requirements  should  not  be
  836.             allowed to exceed available RAM or there will be trouble.
  837.             
  838.             
  839.             3.2  SEMAPHORES
  840.             
  841.             Semaphores (event  flags) are  used to synchronize two tasks
  842.             to the  occurrence of  an asynchronous  event.  One task may
  843.             need to  wait for  the other to reach a certain point before
  844.             it can  continue.  Input/output operations are an example of
  845.             this type  of synchronization.   For instance, when an input
  846.             from an  external device  is desired by a task, it must wait
  847.             for the  input event  to occur.  When the input operation is
  848.             completed, the  device driver  signals that  the  event  has
  849.             occurred  which  indicates  the  data  is  available.    The
  850.             signalling  process  causes  the  waiting  task  to  resume,
  851.  
  852.  
  853.  
  854.  
  855.            Copyright (c) 1989          Page 3 - 3          Motorola, Inc.
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.                   MCX11 - MicroController eXecutive for the 68HC11
  863.  
  864.  
  865.  
  866.             presumably to process the input data. The synchronization of
  867.             the task with the event is done with the use of a semaphore.
  868.             
  869.             There are  several forms  that a  semaphore may  take in the
  870.             design of  a real-time kernel.  MCX11 uses a basic semaphore
  871.             construct that  is known to handle most events and is low in
  872.             overhead.  A   semaphore  is   referenced  by   a  numerical
  873.             identifier limited  to  a  value  from  1-255.  A  semaphore
  874.             identifier of  zero has  a special  meaning. There are three
  875.             different classes of semaphores used by MCX11 as follows:
  876.             
  877.                 -     Named semaphores
  878.                 -     Task semaphores
  879.                 -     Queue semaphores
  880.             
  881.             Named semaphores  are those  normally referenced by the user
  882.             in the  application code. Task and queue semaphores are used
  883.             by MCX11  internally for  the purpose  of orthogonality with
  884.             the semaphore  service functions. Task semaphores are always
  885.             referenced by the identifier of zero (0) which is translated
  886.             by MCX11  into the  proper number  for the  task  semaphore.
  887.             Queue semaphores should never be referenced by the user lest
  888.             undesirable results should occur.
  889.             
  890.             An MCX11  semaphore is a single byte (8 bits) which contains
  891.             a value  representing one  of the  three possible  states in
  892.             which it can exist.  These states are:
  893.             
  894.                 -     PENDING
  895.                 -     WAITING
  896.                 -     DONE
  897.             
  898.             A PENDING state indicates that the event associated with the
  899.             semaphore has  not yet  occurred and  is therefore  pending.
  900.             The WAITING  state shows that not only has the event not yet
  901.             occurred but  a task  is waiting for it to happen.  The DONE
  902.             state tells  that the  event has occurred.  MCX11 semaphores
  903.             have a  very  strict  state  transition  protocol  which  is
  904.             automatically managed  by  MCX11.    The  permissible  state
  905.             changes are shown below in Figure 3-1.
  906.             
  907.             
  908.                             +------- PENDING------- +
  909.                             |           ^           |
  910.                             |   |------ |           |
  911.                             v   |                   v
  912.                             DONE<--------------- WAITING
  913.             
  914.                                      Figure 3.1
  915.             
  916.             
  917.  
  918.  
  919.  
  920.  
  921.            Copyright (c) 1989          Page 3 - 4          Motorola, Inc.
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.                   MCX11 - MicroController eXecutive for the 68HC11
  929.  
  930.  
  931.  
  932.             If a  task attempts  to wait  on a semaphore which is in the
  933.             DONE state,  the  wait  does  not  occur  and  the  task  is
  934.             immediately resumed  (since the  desired event  has  already
  935.             happened)  and  the  semaphore  state  is  changed  back  to
  936.             PENDING.   If a  task attempts to wait on a semaphore in the
  937.             PENDING state,  the state  of the  semaphore is  changed  to
  938.             WAITING and  the task's  execution is  suspended  until  the
  939.             event occurs.  An attempt  to wait  on a  semaphore which is
  940.             already in the WAITING state can cause unpredictable results
  941.             and should  not be  attempted. It  should  be  considered  a
  942.             design error.
  943.             
  944.             If an  attempt is  made to  signal a semaphore which is in a
  945.             PENDING state,  the semaphore is placed into the DONE state.
  946.             As this  action does not concern any task, no further action
  947.             is taken.   However,  if a  signal is sent to a semaphore in
  948.             the WAITING state, the semaphore transitions to a DONE state
  949.             and the  task waiting  on the  event is made runnable again.
  950.             The semaphore  is then  automatically set  back to a PENDING
  951.             state by MCX11.
  952.             
  953.             
  954.             3.3  MESSAGES AND MAILBOXES
  955.             
  956.             Messages are  one of  the means by which data is transmitted
  957.             from a  sender to  a receiver task. Every task running under
  958.             MCX11  is  capable  of  being  both  a  message  sender  and
  959.             receiver. Each  task is  assigned a "mailbox" into which are
  960.             placed all  messages sent  to it. When a sender task sends a
  961.             message, it is put into the mailbox of the receiver task. If
  962.             two or more tasks are sending messages to a single receiver,
  963.             their messages  are put  into the mailbox in strict sequence
  964.             of their priorities, highest priority first.
  965.             
  966.             The content  of the  message is  not actually moved from the
  967.             sender to  the receiver  when it  is sent. Instead, messages
  968.             are linked  into a threaded list according to the priorities
  969.             of their  senders. When the receiver requests receipt of the
  970.             next  message,  its  address  is  returned.  This  technique
  971.             guarantees the receiver that the highest priority message is
  972.             received first.  It is  possible,  however,  to  temporarily
  973.             suspend this  order by requesting only those messages from a
  974.             particular sender.  This is  useful when it is desirable not
  975.             to mix  messages  on  a  shared  resource,  for  example,  a
  976.             printer.
  977.             
  978.             The mailbox  of a  task is  a threaded  (linked) list of all
  979.             messages sent  to but  not yet  received by  that task.  The
  980.             mailbox consists  of a pointer (link) to the message sent by
  981.             the highest  priority sender.  That message is linked to the
  982.             next highest  priority message  and it  in turn is linked to
  983.             the third  highest priority message, and so on until the end
  984.  
  985.  
  986.  
  987.            Copyright (c) 1989          Page 3 - 5          Motorola, Inc.
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.                   MCX11 - MicroController eXecutive for the 68HC11
  995.  
  996.  
  997.  
  998.             of the  thread. The  last message  in a  task's mailbox will
  999.             contain a NULL (value of zero) link.
  1000.             
  1001.             Messages may  be sent with or without waiting for a response
  1002.             from the  receiver. When  a task wants to send a message and
  1003.             wait until  the receiver  has processed the message, it will
  1004.             include a  semaphore number  as one  of the arguments in the
  1005.             MCX11   send  message  directive.  That  semaphore  is  then
  1006.             associated with  the event  of completed  processing of  the
  1007.             message. Once  the message is linked into the mailbox of the
  1008.             receiver task,  the sender  is put  into a WAIT state on the
  1009.             message processing complete event.
  1010.             
  1011.             The receiver  removes  the  message  from  the  mailbox  and
  1012.             processes it  according to  the content of the message body.
  1013.             When the  receiver no  longer needs  the data in the body of
  1014.             the message,  it signals  the semaphore  associated with the
  1015.             completion of  message processing   making  the sender  task
  1016.             runnable again  and, thereby,  allowing it  to continue  its
  1017.             operation.
  1018.             
  1019.             It should  be remembered  that the  body of  the message can
  1020.             also be  used by the receiver to send a response back to the
  1021.             sender. This  is a  very efficient  way of  passing data bi-
  1022.             directionally between two tasks with little overhead.
  1023.             
  1024.             If the  sending task  does not wish to wait on the action of
  1025.             the receiver  or if there is no response required, a message
  1026.             can be  sent without  waiting for  completion of processing.
  1027.             This makes  it  possible  for  a  sender  to  send  multiple
  1028.             messages to  a receiver,  or, simply do something else while
  1029.             the receiver  processes the  message. However, even though a
  1030.             message is  sent without  waiting for  the response,  it  is
  1031.             still possible   at  a later time for the sender to wait for
  1032.             the completion of processing event.
  1033.             
  1034.             If the  receiver has completed the use of the message by the
  1035.             time the  sender waits  for that  event,  the  sending  task
  1036.             continues operation  without interruption.  If the  receiver
  1037.             has not  yet completed processing of the message, the sender
  1038.             must wait  for the  event to  occur. When it does occur, the
  1039.             sender's operation is resumed.
  1040.             
  1041.             A message is a four-element structure set up in a contiguous
  1042.             area of  RAM. The  first three  elements of  the message are
  1043.             used by  MCX11 to  control the  transmission. The  user need
  1044.             only set up the content of the message body. The format of a
  1045.             MCX11 message is as follows:
  1046.             
  1047.                  -    Mailbox link (supplied by MCX11)
  1048.                  -    Task number of sender (supplied by                 
  1049.                       MCX11)
  1050.  
  1051.  
  1052.  
  1053.            Copyright (c) 1989          Page 3 - 6          Motorola, Inc.
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.                   MCX11 - MicroController eXecutive for the 68HC11
  1061.  
  1062.  
  1063.  
  1064.                  -    Message semaphore number (optional)
  1065.                  -    Message body (supplied by User)
  1066.             
  1067.             The first  element in  the message  provides the link to the
  1068.             next message, if any, in the mailbox.
  1069.             
  1070.             The second  element is  the task  number of the sender. This
  1071.             field is  included so that the receiver task can selectively
  1072.             receive only those messages from a specified task.
  1073.             
  1074.             The third  element  of  the  message  contains  an  optional
  1075.             message semaphore  number.   Typically, when  a sending task
  1076.             wants to  send a  message and  wait until  the receiver  has
  1077.             processed the  message, it will include a non-zero semaphore
  1078.             number as  one  of  the  calling  arguments  for  the  MCX11
  1079.             directive. The  sending task  will  then  suspend  execution
  1080.             until the  receiver task  completes the  processing  of  the
  1081.             message content.  When the receiver no longer needs the data
  1082.             in the body of the message, it signals the message semaphore
  1083.             to notify the sender that it may continue processing.
  1084.             .
  1085.             The last  element, the  body, of  the  message  may  contain
  1086.             whatever data  is required  by  the  receiver  task  and  in
  1087.             whatever format.  It may  be fixed  or variable in length as
  1088.             required.
  1089.             
  1090.             
  1091.             3.4  QUEUES
  1092.             
  1093.             MCX11  supports   first-in-first-out  (FIFO)  queues  having
  1094.             single or  multiple bytes per entry.  The queues can support
  1095.             multiple producer/single  consumer service  but are  usually
  1096.             employed in  only a  single producer/single  consumer  mode.
  1097.             Queues are  referenced via  a numerical  identifier which is
  1098.             unique to  each queue.   Queue  numbers are  assigned in the
  1099.             system generation  procedure.    MCX11  queues  differ  from
  1100.             messages in  that the  actual entry  data  rather  than  its
  1101.             address is  entered into or removed from the queue.  Another
  1102.             difference  is   that  the   queue  entries   represent  the
  1103.             chronological order  of processing.  Also, the priorities of
  1104.             the sender  or receiver are not considered as with messages.
  1105.             Queues are  usually used  to handle  data such  as character
  1106.             stream input/output or other data buffering.  Queues require
  1107.             more overhead  as they  move the data from the source to the
  1108.             queue  or   vice  versa  but  they  also  provide  automatic
  1109.             synchronization  between   the  queue's   producer  and  its
  1110.             consumer.   It is  recommended that  they not  be used where
  1111.             high throughput rates are required.
  1112.             
  1113.             A queue  consists of  two parts:   the  queue header and the
  1114.             queue body.   The  queue header  contains  that  information
  1115.             needed by the MCX11 internal routines to enable them to move
  1116.  
  1117.  
  1118.  
  1119.            Copyright (c) 1989          Page 3 - 7          Motorola, Inc.
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.                   MCX11 - MicroController eXecutive for the 68HC11
  1127.  
  1128.  
  1129.  
  1130.             data into  and out of the queues properly.  The organization
  1131.             of the queue header consists of the following elements:
  1132.             
  1133.                 -     Width, queue entry size (in bytes)
  1134.                 -     Depth, maximum length (in entries)
  1135.                 -     Current size of the queue (in entries)
  1136.                 -     Put index (in bytes; MCX11 internal use)
  1137.                 -     Address of queue body
  1138.                 -     Queue not empty semaphore number
  1139.                 -     Active semaphore number
  1140.             
  1141.             The first  three elements  are  defined  during  the  system
  1142.             generation process.   The  Current Size  and the  Put  Index
  1143.             fields are initialized to zero (empty). Both of these fields
  1144.             are  maintained  internally  by  the  MCX11  queue  handling
  1145.             routines. They should never be manipulated by a user task.
  1146.             
  1147.             Semaphores are used to signal internal events such as queue-
  1148.             not- empty  or   queue-not-full. The  semaphores  for  these
  1149.             events are allocated as a consecutive pair during the system
  1150.             initialization process.  The queue-not-full semaphore number
  1151.             is equal to the number of the queue-not-empty semaphore plus
  1152.             one. A  queue can have a semaphore active only for those two
  1153.             mutually exclusive  events. Consequently only the queue-not-
  1154.             empty semaphore  number requires  definition  in  the  queue
  1155.             header.
  1156.             
  1157.             The active  semaphore number  field in  the queue  header is
  1158.             used to  contain the number of the semaphore associated with
  1159.             one of  the two possible events. If the queue is empty and a
  1160.             task attempts to remove an entry, the active semaphore field
  1161.             in the  queue header  is set  to contain  the number  of the
  1162.             queue-not-empty semaphore. Conversely, if a task attempts to
  1163.             put an  entry into a queue which is already full, the active
  1164.             semaphore field  is set  to contain the number of the queue-
  1165.             not-full semaphore.
  1166.             
  1167.             By use  of these  semaphores, it  is possible  to send  data
  1168.             between tasks  asynchronously but without the worry of over-
  1169.             running the queue.
  1170.             
  1171.             
  1172.             3.5 TIMERS
  1173.             
  1174.             In the descriptions of time based functions to follow in the
  1175.             succeeding sections,  it will be important to understand the
  1176.             conventions used  by MCX11.  All timers in MCX11 are 16-bits
  1177.             long. The  two time units used internally by MCX11 are ticks
  1178.             and tocks.   A  tick gives  the amount of time between clock
  1179.             generated system  interrupts, or  equivalently,  the  period
  1180.             between clock interrupt service requests.
  1181.             
  1182.  
  1183.  
  1184.  
  1185.            Copyright (c) 1989          Page 3 - 8          Motorola, Inc.
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.                   MCX11 - MicroController eXecutive for the 68HC11
  1193.  
  1194.  
  1195.  
  1196.             A tock  is an  integral number of ticks and is the time unit
  1197.             used by  all of  the time dependent functions in MCX11.  The
  1198.             tick frequency  of the  RTI clock  is set  during the system
  1199.             initialization process but was determined, as was the number
  1200.             of ticks  per tock,  by the  system  designer  during  MCX11
  1201.             system configuration.
  1202.             
  1203.             As an  example, suppose  the hardware clock is configured to
  1204.             cause interrupts every 25 milliseconds and that 0.25 seconds
  1205.             (250 milliseconds)  is the time most convenient interval for
  1206.             timing events  in the application. In order to determine the
  1207.             number of ticks per tock, simply divide the desired duration
  1208.             of the  tock (250  ms) by  the duration  of a  tick (25 ms).
  1209.             Thus, in this case, 1 tock = 10 ticks.
  1210.             
  1211.             Timer values  are defined  as  the  number  of  clock  tocks
  1212.             required to  form the  needed amount  of time.   If  a timer
  1213.             value is  positive, it  is used  only once (one-shot timer).
  1214.             However, if  the value  is negative,  it is used as a cyclic
  1215.             timer having  a period  equal to  the 2's  complement value.
  1216.             For example,  if a  clock tock  equals 250  milliseconds,  a
  1217.             timer value  of 20  would produce  a once-only  period of  5
  1218.             seconds.   If the  timer were  -20, the  period is  still  5
  1219.             seconds but the timer is cyclic.
  1220.             
  1221.             All timed  event operations  and data structures are handled
  1222.             by MCX11. A task should not attempt to manipulate any of the
  1223.             timer related control or data structures.
  1224.             
  1225.  
  1226.  
  1227.  
  1228.  
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.            Copyright (c) 1989          Page 3 - 9          Motorola, Inc.
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.                   MCX11 - MicroController eXecutive for the 68HC11
  1259.  
  1260.  
  1261.  
  1262.                                      SECTION 4
  1263.                                           
  1264.                          EXECUTIVE SERVICE REQUESTS (ESRS)
  1265.                                           
  1266.             
  1267.             4.1  PURPOSE
  1268.             
  1269.             Executive Service  Requests (ESRs)  are the functions that a
  1270.             real-time kernel  performs and  serve to give it its flavor.
  1271.             This  section   will  describe  the  classes  of  the  MCX11
  1272.             directives.  The directives are divided into five classes as
  1273.             follows:
  1274.             
  1275.                 -     Semaphores
  1276.                 -     Messages
  1277.                 -     Queues
  1278.                 -     Task control
  1279.                 -     Time based
  1280.             
  1281.             A brief  functional description of each ESR within the class
  1282.             is given  along with their respective calling arguments. The
  1283.             calling arguments  needed  for  each  ESR  appear  below  in
  1284.             parentheses. Where  two or more arguments are required, they
  1285.             are separated  by commas.  These are  not the actual calling
  1286.             sequences but  are for  purposes of explanation only. Actual
  1287.             calling sequences are given in Section 5.
  1288.             
  1289.             In the  paragraphs below,  the ESR function name is enclosed
  1290.             within two  periods. This  will be  the convention  used for
  1291.             MCX11 to denote an ESR. The following abbreviations are used
  1292.             below for the arguments:
  1293.             
  1294.                 -     SEMA      Semaphore number
  1295.                 -     TASK      Task number
  1296.                 -     QUEUE     Queue number
  1297.                 -     TOCK      Timer value
  1298.                 -     PNTR      Address pointer or data value
  1299.                 -     MSG       Message address
  1300.             
  1301.             4.2  SEMAPHORE ESRS
  1302.             
  1303.             A complete  set of  directives for  managing  semaphores  is
  1304.             provided by MCX11.
  1305.             
  1306.             
  1307.             .wait. (SEMA)       wait for a specific sema to be signalled
  1308.             .signal. (SEMA)     signal semaphore
  1309.             .pend. (SEMA)       reset semaphore state to PENDing
  1310.             
  1311.             
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.             Copyright (c) 1989         Page 4 - 1          Motorola, Inc.
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.                   MCX11 - MicroController eXecutive for the 68HC11
  1325.  
  1326.  
  1327.  
  1328.             4.3  MESSAGE ESRS
  1329.             
  1330.             The message directives provide a means of transferring large
  1331.             amounts of  data between  tasks with  minimal overhead since
  1332.             only pointers  (addresses)  are  passed.    Message  receipt
  1333.             acknowledgement is  also provided  for task synchronization.
  1334.             The format  of a  MCX11 message  and function prototypes are
  1335.             noted.
  1336.             
  1337.             .send. (MSG,TASK)        send message to a task
  1338.             .sendw. (MSG,TASK,SEMA)  send & wait acknowledgement
  1339.             .receive. (TASK)         receive message
  1340.             
  1341.             
  1342.             4.4  QUEUE ESRS
  1343.             
  1344.             Queue directives  provide a  means of  passing multiple byte
  1345.             packets of  information between  tasks with  automatic  task
  1346.             synchronization of queue full and empty conditions.
  1347.             
  1348.             .dequeue. (QUEUE,PNTR)  remove entry from queue
  1349.             .enqueue. (QUEUE,PNTR)  insert entry into queue
  1350.             
  1351.             
  1352.             4.5  TASK CONTROL ESRS
  1353.             
  1354.             The task  control directives provided by MCX11 allow for low
  1355.             level  complete   control  of  tasks  and  their  respective
  1356.             interactions.
  1357.             
  1358.             .resume. (TASK)         resume specific task
  1359.             .suspend. (TASK)        suspend specific task
  1360.             .terminate. (TASK)      terminate specific task
  1361.             .execute. (TASK)        execute task from starting point
  1362.             
  1363.             
  1364.             4.6  TIME BASED ESRS
  1365.             
  1366.             The time based directives provide for the synchronization of
  1367.             tasks with  timed events.   In  addition, a generalized time
  1368.             based  semaphore   scheme  for   more  advanced  time  based
  1369.             requirements is provided.
  1370.             
  1371.             .delay. (TASK,SEMA,TOCK)  delay task
  1372.             .timer. (TASK,SEMA,TOCK)  schedule timer for task/sema
  1373.             .purge. (TASK,SEMA,PNTR)  purge timer for task/sema
  1374.             
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383.             Copyright (c) 1989         Page 4 - 2          Motorola, Inc.
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.                   MCX11 - MicroController eXecutive for the 68HC11
  1391.  
  1392.  
  1393.  
  1394.                                      SECTION 5
  1395.                                           
  1396.                             ALPHABETICAL LISTING OF ESRs
  1397.                                           
  1398.             
  1399.             In  the   pages  to  follow,  each  ESR  will  be  shown  in
  1400.             alphabetical order.   Each  ESR will  be given in a standard
  1401.             format:
  1402.             
  1403.             Name - brief functional description
  1404.             
  1405.             CLASS
  1406.             
  1407.                  One of the five ESR classes of which it is a member.
  1408.                  
  1409.             SYNOPSIS
  1410.             
  1411.                  The prototype  declaration including  argument  typing.
  1412.                  The decimal  value of  the function code is enclosed in
  1413.                  brackets [xx].
  1414.             
  1415.             DESCRIPTION
  1416.             
  1417.                  A description  of what  the ESR  does, data types used,
  1418.                  etc.
  1419.                  
  1420.             CALLING SEQUENCE
  1421.             
  1422.                  The formal  AS11 calling  sequence  for  the  ESR.  The
  1423.                  following notations will be used:
  1424.                  
  1425.                       ACCA = Accumulator A, 8 bits
  1426.                       ACCB = Accumulator B, 8 bits
  1427.                       IX = Index register X, 16 bits
  1428.                  
  1429.             RETURN VALUE
  1430.             
  1431.                  A description of the return values from the ESR.
  1432.                  
  1433.             EXAMPLE
  1434.             
  1435.                  One or  more typical ESR uses.  The examples assume the
  1436.                  syntax of AS11 cross assembler.
  1437.                  
  1438.             SEE ALSO
  1439.             
  1440.                  List  of   related  ESRs  that  could  be  examined  in
  1441.                  conjunction with the current ESR.
  1442.  
  1443.  
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.             Copyright (c) 1989         Page 5 - 1          Motorola, Inc.
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.                   MCX11 - MicroController eXecutive for the 68HC11
  1457.  
  1458.  
  1459.  
  1460.             5.1  .delay.  -  DELAY A TASK FOR A PERIOD OF TIME
  1461.             
  1462.             CLASS
  1463.             
  1464.                  Timer
  1465.             
  1466.             SYNOPSIS
  1467.             
  1468.                  .delay. (TASK,SEMA,TOCK)       [13]
  1469.             
  1470.             DESCRIPTION
  1471.             
  1472.                  The delay  directive places  the specified  task into a
  1473.                  Wait state  for the  period defined  by the TOCK value.
  1474.                  TASK is  a task  number in the range of 1-126. Or, TASK
  1475.                  may be 0 if the reference is to SELF. Thus, a task need
  1476.                  not know  its own  task number  to schedule a delay for
  1477.                  itself. SEMA  is the  semaphore number  associated with
  1478.                  the  expiration  of  the  timer.  It  may  be  a  named
  1479.                  semaphore if  its number  > 0.  Or, it  may be the task
  1480.                  semaphore of  the calling task if it is specified as 0.
  1481.                  TOCK is  a 16-bit timer. If TOCK is > 0, the timer is a
  1482.                  one-shot. If  TOCK <  0, the  timer is  cyclic. Caution
  1483.                  should be  exercised when  scheduling delays  for other
  1484.                  tasks.
  1485.             
  1486.             CALLING SEQUENCE
  1487.             
  1488.                  ACCA = Task number (0 if SELF)
  1489.                  ACCB = Semaphore number (0 if Task's semaphore)
  1490.                  IX = Number of clock tocks to delay
  1491.                  swi
  1492.                   FCB  .delay.
  1493.                  return
  1494.             
  1495.             RETURN VALUE
  1496.             
  1497.                  None. Registers unchanged.
  1498.             
  1499.             EXAMPLE
  1500.             
  1501.                  Assume that  the RTI  is used  as the time base using a
  1502.                  2**23 crystal  and the  clock TICK  is  defined  to  be
  1503.                  15.625 msec.  Further assume that there are 8 TICKS per
  1504.                  TOCK so  that a TOCK is 125 msec. If a 2.5 sec delay is
  1505.                  desired for  the calling  task using a named semaphore,
  1506.                  TIMEOUT, the request would appear as:
  1507.  
  1508.  
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.             Copyright (c) 1989         Page 5 - 2          Motorola, Inc.
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.                   MCX11 - MicroController eXecutive for the 68HC11
  1523.  
  1524.  
  1525.  
  1526.                  
  1527.                  TOCK      equ   8
  1528.                  TOCKTIME  equ   1000/8         TOCKTIME = 125 msec
  1529.                  TIMEOUT   equ   3              Named semaphore #3
  1530.                            .
  1531.                            :
  1532.                            clra                 Task is self (ACCA=0)
  1533.                            ldab  #TIMEOUT       Semaphore = TIMEOUT
  1534.                            ldx  #2500/TOCKTIME  Timer = 20 TOCKS
  1535.                            swi
  1536.                             FCB  .delay.
  1537.                            .                    Point of continuation
  1538.                  
  1539.                  The requesting  task would  be put into a WAIT state on
  1540.                  semaphore TIMEOUT  while the  2.5 sec  clock runs down.
  1541.                  When it  expires, TIMEOUT  would be  signalled and  the
  1542.                  task would  continue at  the instruction  following the
  1543.                  FCB declaration.
  1544.             
  1545.             SEE ALSO
  1546.             
  1547.                  .timer., .purge.
  1548.  
  1549.  
  1550.  
  1551.  
  1552.  
  1553.  
  1554.  
  1555.  
  1556.  
  1557.  
  1558.  
  1559.  
  1560.  
  1561.  
  1562.  
  1563.  
  1564.  
  1565.  
  1566.  
  1567.  
  1568.  
  1569.  
  1570.  
  1571.  
  1572.  
  1573.  
  1574.  
  1575.  
  1576.  
  1577.  
  1578.  
  1579.  
  1580.  
  1581.             Copyright (c) 1989         Page 5 - 3          Motorola, Inc.
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.                   MCX11 - MicroController eXecutive for the 68HC11
  1589.  
  1590.  
  1591.  
  1592.             5.2  .dequeue.  -  GET AN ENTRY FROM A FIFO QUEUE
  1593.             
  1594.             CLASS
  1595.             
  1596.                  Queue
  1597.             
  1598.             SYNOPSIS
  1599.             
  1600.                  .dequeue. (QUEUE,PNTR)       [7]
  1601.             
  1602.             DESCRIPTION
  1603.             
  1604.                  Dequeue is  used to get an entry from a FIFO queue. The
  1605.                  number of bytes in the entry is determined by the Width
  1606.                  entry in  the Queue  Header. If the queue is empty, the
  1607.                  calling task  is placed into an EVENT WAIT state on the
  1608.                  queue-not-empty semaphore.   If the queue is not empty,
  1609.                  the oldest  entry in  the queue is removed and returned
  1610.                  to the  calling task. If the size of the queue entry is
  1611.                  greater than two bytes, the returned data is in the RAM
  1612.                  area beginning at the address specified by PNTR. If the
  1613.                  queue entry  is one  or two  bytes, PNTR is ignored and
  1614.                  the entry is returned in one or two registers.
  1615.             
  1616.             CALLING SEQUENCE
  1617.             
  1618.                  ACCA= Queue number
  1619.                  IX = Destination address of queue entry if size > 2
  1620.                  swi
  1621.                   FCB .dequeue.
  1622.                  return
  1623.             
  1624.             RETURN VALUE
  1625.             
  1626.                  If queue entry size = 1, ACCA= queue entry
  1627.                  If queue  entry size = 2, ACCA = byte 1 of queue entry,
  1628.                                       and ACCB = byte 2 of queue entry
  1629.                  Other registers unchanged
  1630.             
  1631.             EXAMPLE
  1632.             
  1633.                  Example #1:
  1634.                  
  1635.                  There  exists   a  FIFO  queue,  DBLQ,  containing  two
  1636.                  character entries.  The queue  currently contains  four
  1637.                  entries as follows:
  1638.                  
  1639.                            ab
  1640.                            DE
  1641.                            Mc
  1642.                            xY
  1643.                  
  1644.  
  1645.  
  1646.  
  1647.             Copyright (c) 1989         Page 5 - 4          Motorola, Inc.
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.                   MCX11 - MicroController eXecutive for the 68HC11
  1655.  
  1656.  
  1657.  
  1658.                  A task  is programmed to remove the oldest entry in the
  1659.                  queue and  return it  for  subsequent  processing.  The
  1660.                  entry is dequeued by:
  1661.                  
  1662.                  DBLQ      equ  4              Queue #4
  1663.                            .
  1664.                            :
  1665.                            ldaa  #DBLQ         ACCA = queue # 4
  1666.                            swi
  1667.                             FCB  .dequeue.
  1668.                            .                   Point of continuation
  1669.                  
  1670.                  At the  instruction following the FCB declaration, ACCA
  1671.                  and ACCB will contain the two characters, ab. The queue
  1672.                  will now contain the three entries:
  1673.                  
  1674.                            DE
  1675.                            Mc
  1676.                            xY
  1677.                  
  1678.                  Example #2:
  1679.                  
  1680.                  Another queue  exists, QUADQ,  which contains four byte
  1681.                  entries and  is currently  empty. The request to get an
  1682.                  entry from the queue would appear as:
  1683.                  
  1684.                  QUADQ     equ   5             Queue #5
  1685.                            .
  1686.                            :
  1687.                            ldaa  #QUADQ        ACCA = queue # 5
  1688.                            ldx   #destn        IX = destination address
  1689.                            swi
  1690.                             FCB  .dequeue.
  1691.                            .                   Point of continuation
  1692.                            :
  1693.                  destn     ZMB   4             Where the entry is placed
  1694.                            :
  1695.                  
  1696.                  Since there  are no entries available to dequeue, MCX11
  1697.                  puts the  task into  a  WAIT  state  on  the  NOT_EMPTY
  1698.                  semaphore associated  with  queue  #5.  The  task  will
  1699.                  remain in  that state  until another task puts a 4-byte
  1700.                  entry into  QUADQ. When  that happens, the waiting task
  1701.                  is put  into the RUN state. The entry is removed and is
  1702.                  stored at the specified destination address, destn, and
  1703.                  the task continues at the instruction following the FCB
  1704.                  declaration.
  1705.             
  1706.             SEE ALSO
  1707.             
  1708.                  .enqueue.
  1709.  
  1710.  
  1711.  
  1712.  
  1713.             Copyright (c) 1989         Page 5 - 5          Motorola, Inc.
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.                   MCX11 - MicroController eXecutive for the 68HC11
  1721.  
  1722.  
  1723.  
  1724.             5.3  .enqueue.  -  INSERT DATA INTO FIFO QUEUE
  1725.             
  1726.             CLASS
  1727.             
  1728.                  Queue
  1729.             
  1730.             SYNOPSIS
  1731.             
  1732.                  .enqueue. (QUEUE,PNTR)     [8]
  1733.             
  1734.             DESCRIPTION
  1735.             
  1736.                  Enqueue inserts  an entry  into a  FIFO queue.   If the
  1737.                  queue is  full, the calling task is set to a WAIT state
  1738.                  on the queue NOT FULL condition.  When the queue is not
  1739.                  full, the  entry is  inserted into  the queue.  If  the
  1740.                  width of  the queue  entry is greater than 2 bytes, the
  1741.                  data to  be put  into the queue is found at the address
  1742.                  specified by  the contents of register IX. If the width
  1743.                  is 1  byte, the  actual data to be enqueued is found in
  1744.                  bits 8-15 of IX. If the width is equal to 2 bytes, then
  1745.                  byte 1  of the  entry is  found in bits 8-15 of IX, and
  1746.                  byte 2 is in bits 0-7 of IX.
  1747.             
  1748.             CALLING SEQUENCE
  1749.             
  1750.                  ACCA= Queue number
  1751.                  IX = Source address of entry to be enqueued if size > 2
  1752.                       Or, IX8-15 = byte to be enqueued if size = 1
  1753.                       Or, IX8-15 = byte 1 and IX0-7 = byte 2 if size = 2
  1754.                  swi
  1755.                   FCB .enqueue.
  1756.                  return
  1757.             
  1758.             RETURN VALUE
  1759.             
  1760.                  None. Registers unchanged.
  1761.             
  1762.             EXAMPLE
  1763.             
  1764.                  Example #1:
  1765.                  
  1766.                  Using the  2-byte queue,  DBLQ, defined  above, a  task
  1767.                  wants to  put an  entry into  it. Assume that the queue
  1768.                  contents are the three entries:
  1769.                  
  1770.                            DE
  1771.                            Mc
  1772.                            xY
  1773.                  
  1774.                  The queue  entry size  is two  bytes which  permits the
  1775.                  entry to  be passed  to the  queue routine  in ACCA and
  1776.  
  1777.  
  1778.  
  1779.             Copyright (c) 1989         Page 5 - 6          Motorola, Inc.
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.                   MCX11 - MicroController eXecutive for the 68HC11
  1787.  
  1788.  
  1789.  
  1790.                  ACCB. The  request to  put a  two-byte entry,  LW, into
  1791.                  DBLQ is:
  1792.                  
  1793.                            ldaa  #DBLQ         ACCA = queue # 4
  1794.                            ldx   #"LW"         IX = "LW"
  1795.                            swi
  1796.                             FCB  .enqueue.
  1797.                            .                   Point of continuation
  1798.                  
  1799.                  Since the  queue has content, no task is waiting for an
  1800.                  entry to  dequeue; therefore, the entry is put into the
  1801.                  queue following  the "xY"  entry and the task continues
  1802.                  at the  instruction following  the FCB. The new content
  1803.                  of DBLQ is:
  1804.                  
  1805.                            DE
  1806.                            Mc
  1807.                            xY
  1808.                            LW
  1809.                  
  1810.                  
  1811.                  Example #2:
  1812.                  
  1813.                  Using the  queue, QUADQ,  previously  defined  but  now
  1814.                  containing three entries:
  1815.                  
  1816.                            abcd
  1817.                            EFGH
  1818.                            iJkL
  1819.                  
  1820.                  A request  to put  a new entry into the queue, MnOp, is
  1821.                  given by:
  1822.                  
  1823.                            ldaa  #QUADQ        ACCA = queue # 5
  1824.                            ldx   #srcadr       IX = source address
  1825.                            swi
  1826.                             FCB  .enqueue.
  1827.                            .                   Point of continuation
  1828.                            :
  1829.                  srcadr    FCC   "MnOp"
  1830.                            :
  1831.                  
  1832.                  Since the entry size is four bytes, IX must contain the
  1833.                  address of  the entry  to be enqueued. After continuing
  1834.                  at the instruction following the FCB declaration, QUADQ
  1835.                  contains:
  1836.                  
  1837.                            abcd
  1838.                            EFGH
  1839.                            IjKl
  1840.                            MnOp
  1841.             
  1842.  
  1843.  
  1844.  
  1845.             Copyright (c) 1989         Page 5 - 7          Motorola, Inc.
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.                   MCX11 - MicroController eXecutive for the 68HC11
  1853.  
  1854.  
  1855.  
  1856.             SEE ALSO
  1857.             
  1858.                  .dequeue.
  1859.  
  1860.  
  1861.  
  1862.  
  1863.  
  1864.  
  1865.  
  1866.  
  1867.  
  1868.  
  1869.  
  1870.  
  1871.  
  1872.  
  1873.  
  1874.  
  1875.  
  1876.  
  1877.  
  1878.  
  1879.  
  1880.  
  1881.  
  1882.  
  1883.  
  1884.  
  1885.  
  1886.  
  1887.  
  1888.  
  1889.  
  1890.  
  1891.  
  1892.  
  1893.  
  1894.  
  1895.  
  1896.  
  1897.  
  1898.  
  1899.  
  1900.  
  1901.  
  1902.  
  1903.  
  1904.  
  1905.  
  1906.  
  1907.  
  1908.  
  1909.  
  1910.  
  1911.             Copyright (c) 1989         Page 5 - 8          Motorola, Inc.
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.                   MCX11 - MicroController eXecutive for the 68HC11
  1919.  
  1920.  
  1921.  
  1922.             5.4  .execute.  -  EXECUTE A TASK
  1923.             
  1924.             CLASS
  1925.             
  1926.                  Task control
  1927.             
  1928.             SYNOPSIS
  1929.             
  1930.                  .execute. (TASK)     [12]
  1931.             
  1932.             DESCRIPTION
  1933.             
  1934.                  The execute  task directive is used to start or restart
  1935.                  a task from its beginning. The program counter (PC) and
  1936.                  stack pointer  (SP) are  initialized to  their starting
  1937.                  values and the specified task is made runnable.  If the
  1938.                  new task is of higher priority than the current task, a
  1939.                  context switch is performed and the new task runs, else
  1940.                  control is  returned to  the  caller.  The  task  being
  1941.                  started cannot be SELF (task number argument = 0).
  1942.             
  1943.             CALLING SEQUENCE
  1944.             
  1945.                  ACCA= Task number
  1946.                  swi
  1947.                   FCB .execute.
  1948.                  return
  1949.             
  1950.             RETURN VALUE
  1951.             
  1952.                  None. Registers unchanged.
  1953.             
  1954.             EXAMPLE
  1955.             
  1956.                  The current task wishes to cause task number 6 to begin
  1957.                  execution at  its starting  point.  Task  number  6  is
  1958.                  currently IDLE. The request appears as:
  1959.                  
  1960.                  TASK6     equ   6             Task #6
  1961.                            .
  1962.                            :
  1963.                            ldaa  #TASK6        ACCA = task # 6
  1964.                            swi
  1965.                             FCB  .execute.
  1966.                            .                   Point of continuation
  1967.                  
  1968.                  If TASK6  is of  higher priority, then the current task
  1969.                  is interrupted,  but still  runnable, and TASK6 is made
  1970.                  the current task. The task which scheduled TASK6 is not
  1971.                  given control  again until  all other  higher  priority
  1972.                  tasks, including  TASK6, are not runnable. When it does
  1973.                  continue, it will do so following the FCB declaration.
  1974.  
  1975.  
  1976.  
  1977.             Copyright (c) 1989         Page 5 - 9          Motorola, Inc.
  1978.  
  1979.  
  1980.  
  1981.  
  1982.  
  1983.  
  1984.                   MCX11 - MicroController eXecutive for the 68HC11
  1985.  
  1986.  
  1987.  
  1988.                  
  1989.                  If TASK6 is of lower priority that the current task, no
  1990.                  context switch occurs and the current task continues at
  1991.                  the instruction following the FCB declaration.
  1992.             
  1993.             SEE ALSO
  1994.             
  1995.                  .terminate.
  1996.  
  1997.  
  1998.  
  1999.  
  2000.  
  2001.  
  2002.  
  2003.  
  2004.  
  2005.  
  2006.  
  2007.  
  2008.  
  2009.  
  2010.  
  2011.  
  2012.  
  2013.  
  2014.  
  2015.  
  2016.  
  2017.  
  2018.  
  2019.  
  2020.  
  2021.  
  2022.  
  2023.  
  2024.  
  2025.  
  2026.  
  2027.  
  2028.  
  2029.  
  2030.  
  2031.  
  2032.  
  2033.  
  2034.  
  2035.  
  2036.  
  2037.  
  2038.  
  2039.  
  2040.  
  2041.  
  2042.  
  2043.             Copyright (c) 1989         Page 5 - 10          Motorola, Inc.
  2044.  
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050.                   MCX11 - MicroController eXecutive for the 68HC11
  2051.  
  2052.  
  2053.  
  2054.             5.5  .pend.  -  FORCE A SEMAPHORE TO A PENDING STATE
  2055.             
  2056.             CLASS
  2057.             
  2058.                  Semaphore
  2059.             
  2060.             SYNOPSIS
  2061.             
  2062.                  .pend. (SEMA)       [3]
  2063.             
  2064.             DESCRIPTION
  2065.             
  2066.                  To understand  the use  of the  pend directive,  recall
  2067.                  that the  WAIT directive  will return  control  to  the
  2068.                  calling task  immediately if  the task requests to wait
  2069.                  on a semaphore found to already be in a DONE state.  In
  2070.                  this  sense,   semaphores  keep   a  history  of  their
  2071.                  associated events,  even if  no task  is waiting at the
  2072.                  time  of   the  signal.     If   a  task  needs  to  go
  2073.                  unconditionally into a Event Wait state on a semaphore,
  2074.                  a call should first be made to PEND followed closely by
  2075.                  a WAIT directive.
  2076.             
  2077.             CALLING SEQUENCE
  2078.             
  2079.                  ACCB = Semaphore number
  2080.                  swi
  2081.                   FCB .pend.
  2082.                  return
  2083.             
  2084.             RETURN VALUE
  2085.             
  2086.                  None. Registers unchanged.
  2087.             
  2088.             EXAMPLE
  2089.             
  2090.                  The current  task is  going to  make use of a semaphore
  2091.                  and wants  to be  certain of its state prior to use. It
  2092.                  forces the  semaphore into  a PENDing  condition by the
  2093.                  following request:
  2094.                  
  2095.                  NEWSEMA   equ   14            Semaphore #14
  2096.                            .
  2097.                            :
  2098.                            ldab  #NEWSEMA      ACCB = semaphore # 14
  2099.                            swi
  2100.                             FCB  .pend.
  2101.                            .                   Point of continuation
  2102.             
  2103.             SEE ALSO
  2104.             
  2105.                  .wait.
  2106.  
  2107.  
  2108.  
  2109.             Copyright (c) 1989         Page 5 - 11          Motorola, Inc.
  2110.  
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116.                   MCX11 - MicroController eXecutive for the 68HC11
  2117.  
  2118.  
  2119.  
  2120.             5.6  .purge.  -  PURGE A TASK'S TIMERS
  2121.             
  2122.             CLASS
  2123.             
  2124.                  Timer
  2125.             
  2126.             SYNOPSIS
  2127.             
  2128.                  .purge. (TASK,SEMA,PNTR)      [15]
  2129.             
  2130.             DESCRIPTION
  2131.             
  2132.                  The purge  timer directive is used to remove all active
  2133.                  timers for  the specified  task or semaphore number.  A
  2134.                  specification of a zero semaphore number will purge all
  2135.                  semaphore timers for the given task.  When the purge is
  2136.                  completed, the current task is resumed.
  2137.             
  2138.             CALLING SEQUENCE
  2139.             
  2140.                  ACCA = Task number (0 if SELF)
  2141.                  ACCB = Semaphore number (0 if task semaphore)
  2142.                  IX0-7 = Switch: 0 = purge all timers for given task
  2143.                                 >0 = purge time for given task & sema
  2144.                  swi
  2145.                   FCB .purge.
  2146.                  return
  2147.             
  2148.             RETURN VALUE
  2149.             
  2150.                  None. Registers unchanged.
  2151.             
  2152.             EXAMPLE
  2153.             
  2154.                  The most common use of this ESR is for the current task
  2155.                  to get  rid of  one or  all of its active timers. Since
  2156.                  timers are  associated with semaphores, the combination
  2157.                  of task  number and  semaphore number  is sufficient to
  2158.                  identify a  timer uniquely.  The request  to purge  the
  2159.                  current task's timer associated with the task semaphore
  2160.                  appears as:
  2161.                  
  2162.                            clra                ACCA = 0 means SELF
  2163.                            clrb                ACCB = 0 means task sema
  2164.                            ldx   #1            Only purge one timer
  2165.                            swi
  2166.                             FCB  .purge.
  2167.                            .                   Point of continuation
  2168.                  
  2169.  
  2170.  
  2171.  
  2172.  
  2173.  
  2174.  
  2175.             Copyright (c) 1989         Page 5 - 12          Motorola, Inc.
  2176.  
  2177.  
  2178.  
  2179.  
  2180.  
  2181.  
  2182.                   MCX11 - MicroController eXecutive for the 68HC11
  2183.  
  2184.  
  2185.  
  2186.                  If all  timers for a task are to be purged, the request
  2187.                  appears as:
  2188.                  
  2189.                            clra                ACCA = 0 means SELF
  2190.                            ldx   #0            Purge all timers
  2191.                            swi
  2192.                             FCB  .purge.
  2193.                            .                   Point of continuation
  2194.             
  2195.             SEE ALSO
  2196.             
  2197.                  .timer., .terminate.
  2198.             
  2199.  
  2200.  
  2201.  
  2202.  
  2203.  
  2204.  
  2205.  
  2206.  
  2207.  
  2208.  
  2209.  
  2210.  
  2211.  
  2212.  
  2213.  
  2214.  
  2215.  
  2216.  
  2217.  
  2218.  
  2219.  
  2220.  
  2221.  
  2222.  
  2223.  
  2224.  
  2225.  
  2226.  
  2227.  
  2228.  
  2229.  
  2230.  
  2231.  
  2232.  
  2233.  
  2234.  
  2235.  
  2236.  
  2237.  
  2238.  
  2239.  
  2240.  
  2241.             Copyright (c) 1989         Page 5 - 13          Motorola, Inc.
  2242.  
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248.                   MCX11 - MicroController eXecutive for the 68HC11
  2249.  
  2250.  
  2251.  
  2252.             5.7  .receive.  -  RECEIVE A MESSAGE
  2253.             
  2254.             CLASS
  2255.             
  2256.                  Message
  2257.             
  2258.             SYNOPSIS
  2259.             
  2260.                  .receive. (TASK)       [6]
  2261.             
  2262.             DESCRIPTION
  2263.             
  2264.                  The receive message directive is used to fetch messages
  2265.                  from a  calling task's  mailbox.   Because the messages
  2266.                  are placed  in the mailbox in the order of the sender's
  2267.                  priority, they  are processed in the same sequence.  If
  2268.                  the receiving  task specifies  a non-zero  task number,
  2269.                  the first  message from  that task  will  be  returned.
  2270.                  With a  zero task  number, the  first  message  in  the
  2271.                  mailbox is  returned.   If there are no messages in the
  2272.                  mailbox, the  task's context  is saved, and the task is
  2273.                  put into  a Message  WAIT state.  When the next message
  2274.                  is sent  to the task it will be resumed and the attempt
  2275.                  to receive a message will be reissued.
  2276.             
  2277.             CALLING SEQUENCE
  2278.             
  2279.                  ACCA =  Task number  if messages from specific task are
  2280.                         wanted. Or, ACCA = 0 if highest priority message
  2281.                         is wanted.
  2282.                  swi
  2283.                   FCB .receive.
  2284.                  return
  2285.             
  2286.             RETURN VALUE
  2287.             
  2288.                  Register  IX  contains  the  address  of  the  received
  2289.                  message. Other registers unchanged.
  2290.             
  2291.             EXAMPLE
  2292.             
  2293.                  Example #1:
  2294.                  
  2295.                  The current  task is  a server which operates only when
  2296.                  another task  sends it  a  message  instructing  it  to
  2297.                  perform  some   function.  The   server  task  receives
  2298.                  messages by making a request such as:
  2299.                  
  2300.                            clra                0 = next message
  2301.                            swi
  2302.                             FCB  .receive.
  2303.                            .                   Point of continuation
  2304.  
  2305.  
  2306.  
  2307.             Copyright (c) 1989         Page 5 - 14          Motorola, Inc.
  2308.  
  2309.  
  2310.  
  2311.  
  2312.  
  2313.  
  2314.                   MCX11 - MicroController eXecutive for the 68HC11
  2315.  
  2316.  
  2317.  
  2318.                  
  2319.                  The server  task will  not continue  unless there  is a
  2320.                  message waiting  in its  mailbox. It will be put into a
  2321.                  WAIT state  until such  time as another task sends it a
  2322.                  message. No  waiting occurs  if a message is already in
  2323.                  the mailbox  at the  time  of  the  request.  When  the
  2324.                  message is available, its address is returned in the IX
  2325.                  register.
  2326.                  
  2327.                  Example #2:
  2328.                  
  2329.                  If the server wants to receive only those messages from
  2330.                  a specific  task, and  the task's number is to be found
  2331.                  in a variable named 'attach', the request is:
  2332.                  
  2333.                            ldaa  attach        variable contains task #
  2334.                            swi
  2335.                             FCB  .receive.
  2336.                            .                   Point of continuation
  2337.                            :
  2338.                  attach    ZMB   1
  2339.                  
  2340.                  The server  task will now only listen for messages from
  2341.                  the task  whose number is in the variable 'attach'. All
  2342.                  other messages  will  remain  in  the  mailbox  of  the
  2343.                  server. The  server will  continue  only  when  it  has
  2344.                  received a message from the specific task.
  2345.             
  2346.             SEE ALSO
  2347.             
  2348.                  .send., .sendw.
  2349.             
  2350.  
  2351.  
  2352.  
  2353.  
  2354.  
  2355.  
  2356.  
  2357.  
  2358.  
  2359.  
  2360.  
  2361.  
  2362.  
  2363.  
  2364.  
  2365.  
  2366.  
  2367.  
  2368.  
  2369.  
  2370.  
  2371.  
  2372.  
  2373.             Copyright (c) 1989         Page 5 - 15          Motorola, Inc.
  2374.  
  2375.  
  2376.  
  2377.  
  2378.  
  2379.  
  2380.                   MCX11 - MicroController eXecutive for the 68HC11
  2381.  
  2382.  
  2383.  
  2384.             5.8  .resume.  -  RESUME A TASK
  2385.             
  2386.             CLASS
  2387.             
  2388.                  Task control
  2389.             
  2390.             SYNOPSIS
  2391.             
  2392.                  .resume. (TASK)       [9]
  2393.             
  2394.             DESCRIPTION
  2395.             
  2396.                  The resume  directive clears  the suspended  state of a
  2397.                  task caused  by a  suspend directive.   If  the resumed
  2398.                  task is  made runnable  and is  higher priority, a task
  2399.                  switch is performed.  Otherwise, control is returned to
  2400.                  the calling task.
  2401.             
  2402.             CALLING SEQUENCE
  2403.             
  2404.                  ACCA = Task number
  2405.                  swi
  2406.                   FCB .resume.
  2407.                  return
  2408.             
  2409.             RETURN VALUE
  2410.             
  2411.                  None. Registers unchanged.
  2412.             
  2413.             EXAMPLE
  2414.             
  2415.                  A task  which has  been  previously  suspended  may  be
  2416.                  resumed from the point of suspension only by a .resume.
  2417.                  request from another task. The request appears as:
  2418.                  
  2419.                  TASK6     equ   6             Task #6
  2420.                            .
  2421.                            :
  2422.                            ldaa  #TASK6        ACCA = task # 6
  2423.                            swi
  2424.                             FCB  .resume.
  2425.                            .                   Point of continuation
  2426.                  
  2427.                  Upon resuming  the given  task, a  context  switch  may
  2428.                  occur if  the resumed  task is  of higher priority than
  2429.                  the task  making the request. If not, no context switch
  2430.                  occurs.  The   requesting   task   continues   at   the
  2431.                  instruction following the FCB.
  2432.             
  2433.             SEE ALSO
  2434.             
  2435.                  .suspend.
  2436.  
  2437.  
  2438.  
  2439.             Copyright (c) 1989         Page 5 - 16          Motorola, Inc.
  2440.  
  2441.  
  2442.  
  2443.  
  2444.  
  2445.  
  2446.                   MCX11 - MicroController eXecutive for the 68HC11
  2447.  
  2448.  
  2449.  
  2450.             5.9  .send.  -  SEND A MESSAGE TO A TASK
  2451.             
  2452.             CLASS
  2453.             
  2454.                  Message
  2455.             
  2456.             SYNOPSIS
  2457.             
  2458.                  .send. (MSG,TASK)       [4]
  2459.             
  2460.             DESCRIPTION
  2461.             
  2462.                  The send  message directive  inserts a message into the
  2463.                  target task's  mailbox in  the  order  of  the  sending
  2464.                  task's priority.   If  the receiving task is waiting to
  2465.                  receive a  message and  is of  higher priority than the
  2466.                  sender, a  task switch  is performed.  If the receiving
  2467.                  task is  of lower  priority and  waiting on  a message,
  2468.                  then the  receiving task is marked runnable but control
  2469.                  is  returned  on  a  message,  the  message  is  simply
  2470.                  inserted to his mailbox for later receipt.
  2471.             
  2472.             CALLING SEQUENCE
  2473.             
  2474.                  ACCA = Task number of the receiver
  2475.                  ACCB = Semaphore number (task semaphore number = 0)
  2476.                  IX = Message address
  2477.                  swi
  2478.                   FCB .send.
  2479.                  return
  2480.             
  2481.             RETURN VALUE
  2482.             
  2483.                  None.  ACCB   will  contain  the  number  of  the  task
  2484.                  semaphore if  ACCB was  = 0  at time  of swi. All other
  2485.                  registers unchanged.
  2486.             
  2487.             EXAMPLE
  2488.             
  2489.                  A task wishing to send a message to a receiver task can
  2490.                  do so by the following code:
  2491.                  
  2492.  
  2493.  
  2494.  
  2495.  
  2496.  
  2497.  
  2498.  
  2499.  
  2500.  
  2501.  
  2502.  
  2503.  
  2504.  
  2505.             Copyright (c) 1989         Page 5 - 17          Motorola, Inc.
  2506.  
  2507.  
  2508.  
  2509.  
  2510.  
  2511.  
  2512.                   MCX11 - MicroController eXecutive for the 68HC11
  2513.  
  2514.  
  2515.  
  2516.                  RCVRTSK   equ   12            Receiving task = task #12
  2517.                  MSGSEMA   equ   7             Use sema #7 for Message
  2518.                            .
  2519.                            :
  2520.                            ldaa  #RCVRTSK      ACCA = receiver task #
  2521.                            ldab  #MSGSEMA      ACCB = Message semaphore
  2522.                            ldx   #msgadr       IX = Address of message
  2523.                            swi
  2524.                             FCB  .send.
  2525.                            .                   Point of continuation
  2526.                            :
  2527.                  msgadr    ZMB   4             Message overhead
  2528.                            FCC   "THIS IS THE MESSAGE BODY"
  2529.                  
  2530.                  The message  located at  'msgadr' will  be put into the
  2531.                  mailbox of RCVRTSK. Processing in the sending task will
  2532.                  resume   at   the   instruction   following   the   FCB
  2533.                  declaration.
  2534.             
  2535.             SEE ALSO
  2536.             
  2537.                  .receive., .sendw.
  2538.  
  2539.  
  2540.  
  2541.  
  2542.  
  2543.  
  2544.  
  2545.  
  2546.  
  2547.  
  2548.  
  2549.  
  2550.  
  2551.  
  2552.  
  2553.  
  2554.  
  2555.  
  2556.  
  2557.  
  2558.  
  2559.  
  2560.  
  2561.  
  2562.  
  2563.  
  2564.  
  2565.  
  2566.  
  2567.  
  2568.  
  2569.  
  2570.  
  2571.             Copyright (c) 1989         Page 5 - 18          Motorola, Inc.
  2572.  
  2573.  
  2574.  
  2575.  
  2576.  
  2577.  
  2578.                   MCX11 - MicroController eXecutive for the 68HC11
  2579.  
  2580.  
  2581.  
  2582.             5.10  .sendw.  -  SEND A MESSAGE AND WAIT
  2583.             
  2584.             CLASS
  2585.             
  2586.                  Message
  2587.             
  2588.             SYNOPSIS
  2589.             
  2590.                  .sendw. (MSG,TASK,SEMA)       [5]
  2591.             
  2592.             DESCRIPTION
  2593.             
  2594.                  The send  message and  wait directive is similar to the
  2595.                  send message directive described above, except that the
  2596.                  sending task  is always  put into a Event Wait state on
  2597.                  the message  semaphore.  This allows the receiving task
  2598.                  to signal  the sender  when the  message processing  is
  2599.                  complete and/or  that there  is data  returned  in  the
  2600.                  message area.
  2601.             
  2602.             CALLING SEQUENCE
  2603.             
  2604.                  ACCA = Task number of the receiver
  2605.                  ACCB = Semaphore number (task semaphore number = 0)
  2606.                  IX = Message address
  2607.                  swi
  2608.                   FCB .sendw.
  2609.                  return
  2610.             
  2611.             RETURN VALUE
  2612.             
  2613.                  None.  ACCB   will  contain  the  number  of  the  task
  2614.                  semaphore if  ACCB was  = 0  at time  of swi. All other
  2615.                  registers unchanged.
  2616.             
  2617.             EXAMPLE
  2618.             
  2619.                  The example  is the  same as for .send. except that the
  2620.                  ESR request  will be  .sendw. Another difference is the
  2621.                  WAIT state  into which the sending task is placed until
  2622.                  the receiving task signals the message semaphore. Until
  2623.                  that signal  is received,  the sending task proceeds no
  2624.                  further.  When   the  receiver   signals  the   message
  2625.                  semaphore,  the  sending  task  will  continue  at  the
  2626.                  instruction following the FCB.
  2627.             
  2628.             SEE ALSO
  2629.             
  2630.                  .send., .receive.
  2631.             
  2632.  
  2633.  
  2634.  
  2635.  
  2636.  
  2637.             Copyright (c) 1989         Page 5 - 19          Motorola, Inc.
  2638.  
  2639.  
  2640.  
  2641.  
  2642.  
  2643.  
  2644.                   MCX11 - MicroController eXecutive for the 68HC11
  2645.  
  2646.  
  2647.  
  2648.             5.11  .signal.  -  SIGNAL A SEMAPHORE
  2649.             
  2650.             CLASS
  2651.             
  2652.                  Semaphore
  2653.             
  2654.             SYNOPSIS
  2655.             
  2656.                  .signal. (SEMA)       [2]
  2657.             
  2658.             DESCRIPTION
  2659.             
  2660.                  The signal  semaphore directive  sets the  state  of  a
  2661.                  specified semaphore  to DONE.    If  the  semaphore  is
  2662.                  currently in  a WAIT state, the Event Wait state of the
  2663.                  waiting task  is removed,  and  the  semaphore  is  set
  2664.                  PENDing.   If the  waiting task becomes runnable and is
  2665.                  of  higher  priority  than  the  signalling  task,  the
  2666.                  context of  the current  task is  saved, and  a context
  2667.                  switch is performed.
  2668.                  
  2669.                  If the  state of  the semaphore  was either  PENDing or
  2670.                  DONE, the semaphore is placed in the DONE state and the
  2671.                  current task is resumed following the signal ESR.
  2672.             
  2673.             CALLING SEQUENCE
  2674.             
  2675.                  ACCB = Semaphore number
  2676.                  swi
  2677.                   FCB .signal.
  2678.                  return
  2679.             
  2680.             RETURN VALUE
  2681.             
  2682.                  None. Registers unchanged.
  2683.             
  2684.             EXAMPLE
  2685.             
  2686.                  Assume that  the current  task  wishes  to  signal  the
  2687.                  occurrence  of   a  particular   event.  The  event  is
  2688.                  associated with  a named  semaphore, EVNTSEMA. The task
  2689.                  signals the semaphore by the following procedure:
  2690.                  
  2691.                  EVNTSEMA  equ   15            Named semaphore #15
  2692.                            .
  2693.                            :
  2694.                            ldab  #EVNTSEMA     ACCB = semaphore # 15
  2695.                            swi
  2696.                             FCB  .signal.
  2697.                            .                   Point of continuation
  2698.                  
  2699.  
  2700.  
  2701.  
  2702.  
  2703.             Copyright (c) 1989         Page 5 - 20          Motorola, Inc.
  2704.  
  2705.  
  2706.  
  2707.  
  2708.  
  2709.  
  2710.                   MCX11 - MicroController eXecutive for the 68HC11
  2711.  
  2712.  
  2713.  
  2714.                  Depending on  the  state  of  semaphore  EVNTSEMA,  the
  2715.                  signal may  or may  not cause  a  context  switch.  The
  2716.                  signalling  task   will  continue   processing  at  the
  2717.                  instruction following the FCB declaration.
  2718.             
  2719.             SEE ALSO
  2720.             
  2721.                  .pend., .wait.
  2722.             
  2723.  
  2724.  
  2725.  
  2726.  
  2727.  
  2728.  
  2729.  
  2730.  
  2731.  
  2732.  
  2733.  
  2734.  
  2735.  
  2736.  
  2737.  
  2738.  
  2739.  
  2740.  
  2741.  
  2742.  
  2743.  
  2744.  
  2745.  
  2746.  
  2747.  
  2748.  
  2749.  
  2750.  
  2751.  
  2752.  
  2753.  
  2754.  
  2755.  
  2756.  
  2757.  
  2758.  
  2759.  
  2760.  
  2761.  
  2762.  
  2763.  
  2764.  
  2765.  
  2766.  
  2767.  
  2768.  
  2769.             Copyright (c) 1989         Page 5 - 21          Motorola, Inc.
  2770.  
  2771.  
  2772.  
  2773.  
  2774.  
  2775.  
  2776.                   MCX11 - MicroController eXecutive for the 68HC11
  2777.  
  2778.  
  2779.  
  2780.             5.12  .suspend.  -  SUSPEND A TASK
  2781.             
  2782.             CLASS
  2783.             
  2784.                  Task control
  2785.             
  2786.             SYNOPSIS
  2787.             
  2788.                  .suspend. (TASK)       [10]
  2789.             
  2790.             DESCRIPTION
  2791.             
  2792.                  The suspend  directive causes  the specified task to be
  2793.                  placed into  a suspended  state.   The suspended  state
  2794.                  will remain  in force  until it is removed by a resume,
  2795.                  execute, or  reset  directive.    A  task  may  suspend
  2796.                  itself.  Task 0 indicates the SELF task.
  2797.             
  2798.             CALLING SEQUENCE
  2799.             
  2800.                  ACCA = Task number (this may be SELF [0])
  2801.                  swi
  2802.                   FCB .suspend.
  2803.                  return
  2804.             
  2805.             RETURN VALUE
  2806.             
  2807.                  None. Registers unchanged.
  2808.             
  2809.             EXAMPLE
  2810.             
  2811.                  The current  task wants  to suspend  itself until  some
  2812.                  indeterminate point  in the  future. To do so, it makes
  2813.                  the following request:
  2814.                  
  2815.                            clra                ACCA = 0 means SELF
  2816.                            swi
  2817.                             FCB .suspend.
  2818.                            .                   Point of continuation
  2819.                  
  2820.                  The task  remains in a suspended state until resumed by
  2821.                  a .resume.  ESR issued from another task. At that time,
  2822.                  the resumed  task  will  continue  at  the  instruction
  2823.                  following the FCB declaration.
  2824.             
  2825.             SEE ALSO
  2826.             
  2827.                  .resume.
  2828.  
  2829.  
  2830.  
  2831.  
  2832.  
  2833.  
  2834.  
  2835.             Copyright (c) 1989         Page 5 - 22          Motorola, Inc.
  2836.  
  2837.  
  2838.  
  2839.  
  2840.  
  2841.  
  2842.                   MCX11 - MicroController eXecutive for the 68HC11
  2843.  
  2844.  
  2845.  
  2846.             5.13  .terminate.  -  TERMINATE A TASK
  2847.             
  2848.             CLASS
  2849.             
  2850.                  Task control
  2851.             
  2852.             SYNOPSIS
  2853.             
  2854.                  .terminate. (TASK)       [11]
  2855.             
  2856.             DESCRIPTION
  2857.             
  2858.                  The terminate  directive is  used to terminate a task's
  2859.                  operation.   During termination,  the task's  state  is
  2860.                  cleared and  the task  state is set to Terminated.  The
  2861.                  timer queue  is searched  and all active timers for the
  2862.                  task are  purged.   Also, all  messages pending for the
  2863.                  task are  removed.   A task  number of 0 indicates self
  2864.                  termination.   In all  cases, the highest priority task
  2865.                  will execute next.
  2866.             
  2867.             CALLING SEQUENCE
  2868.             
  2869.                  ACCA = Task number (may be = 0 if terminating SELF)
  2870.                  swi
  2871.                   .terminate.
  2872.                  return
  2873.             
  2874.             RETURN VALUE
  2875.             
  2876.                  None.  Registers   unchanged.  Returns   only  if   not
  2877.                  terminating SELF.
  2878.             
  2879.             EXAMPLE
  2880.             
  2881.                  The current  task commits suicide by terminating itself
  2882.                  with the following procedure:
  2883.                  
  2884.                            clra                ACCA = 0 means SELF
  2885.                            swi
  2886.                             FCB .terminate.
  2887.                  
  2888.                  There is  no point of continuation following a suicide.
  2889.                  If another  task is terminated by the current task, the
  2890.                  current  task   will   continue   processing   at   the
  2891.                  instruction following the FCB declaration.
  2892.             
  2893.             SEE ALSO
  2894.             
  2895.                  .purge.
  2896.  
  2897.  
  2898.  
  2899.  
  2900.  
  2901.             Copyright (c) 1989         Page 5 - 23          Motorola, Inc.
  2902.  
  2903.  
  2904.  
  2905.  
  2906.  
  2907.  
  2908.                   MCX11 - MicroController eXecutive for the 68HC11
  2909.  
  2910.  
  2911.  
  2912.             5.14  .timer.  -  START A TIMER
  2913.             
  2914.             CLASS
  2915.             
  2916.                  Timer
  2917.             
  2918.             SYNOPSIS
  2919.             
  2920.                  .timer. (TASK,SEMA,TOCK)       [14]
  2921.             
  2922.             DESCRIPTION
  2923.             
  2924.                  The timer  directive inserts  an entry of the specified
  2925.                  time duration  into the  timer queue.  The timer can be
  2926.                  cyclic or  one-shot.   Cyclic timers are indicated by a
  2927.                  negative  duration  while  one-shots  are  of  positive
  2928.                  duration.   Further  options  allow  the  timer  to  be
  2929.                  associated either  with a  specified task  number (0  =
  2930.                  SELF) or  a semaphore  number.    After  the  timer  is
  2931.                  inserted,  the  current  task  is  resumed.    See  the
  2932.                  Advanced Topic  section for task versus semaphore-based
  2933.                  timers.
  2934.             
  2935.             CALLING SEQUENCE
  2936.             
  2937.                  ACCA = Task number (0 if SELF)
  2938.                  ACCB = Semaphore number (0 if task's semaphore)
  2939.                  IX = Number of clock tocks in timer. If > 0, timer is a
  2940.                       one-shot. If < 0, timer is cyclic.
  2941.                  swi
  2942.                   FCB .timer.
  2943.                  return
  2944.             
  2945.             RETURN VALUE
  2946.             
  2947.                  None. ACCA will contain the current task number if ACCA
  2948.                  was = 0 at swi. Other registers unchanged.
  2949.             
  2950.             EXAMPLE
  2951.             
  2952.                  Example #1:
  2953.                  
  2954.                  Assume that the current task wants to set up a one-shot
  2955.                  timer of 5 seconds. Also assume that the RTI is used as
  2956.                  the time  base using a 2**23 crystal and the clock TICK
  2957.                  is defined  to be 15.625 msec. Furthermore, there are 8
  2958.                  TICKS per TOCK so that a TOCK is 125 msec. The setup of
  2959.                  a 5  second timer  associated with  a named  semaphore,
  2960.                  TIMEOUT, would appear as:
  2961.                  
  2962.  
  2963.  
  2964.  
  2965.  
  2966.  
  2967.             Copyright (c) 1989         Page 5 - 24          Motorola, Inc.
  2968.  
  2969.  
  2970.  
  2971.  
  2972.  
  2973.  
  2974.                   MCX11 - MicroController eXecutive for the 68HC11
  2975.  
  2976.  
  2977.  
  2978.                  TOCK      equ   8
  2979.                  TOCKTIME  equ   1000/8         TOCKTIME = 125 msec
  2980.                  TIMEOUT   equ   3              Named semaphore #3
  2981.                            .
  2982.                            :
  2983.                            clra                 Task is self (ACCA=0)
  2984.                            ldab  #TIMEOUT       Semaphore = TIMEOUT
  2985.                            ldx  #5000/TOCKTIME  Timer = 40 TOCKS
  2986.                            swi
  2987.                             FCB  .timer.
  2988.                            .                    Point of continuation
  2989.                  
  2990.                  The current  task would continue processing immediately
  2991.                  after the  ESR is finished because the .timer. ESR does
  2992.                  not cause the requestor to be put into a WAIT state nor
  2993.                  is there  a  context  switch  possible.  The  task  may
  2994.                  attempt to  wait on  the timer  semaphore at some later
  2995.                  time.
  2996.             
  2997.             SEE ALSO
  2998.             
  2999.                  .purge.
  3000.  
  3001.  
  3002.  
  3003.  
  3004.  
  3005.  
  3006.  
  3007.  
  3008.  
  3009.  
  3010.  
  3011.  
  3012.  
  3013.  
  3014.  
  3015.  
  3016.  
  3017.  
  3018.  
  3019.  
  3020.  
  3021.  
  3022.  
  3023.  
  3024.  
  3025.  
  3026.  
  3027.  
  3028.  
  3029.  
  3030.  
  3031.  
  3032.  
  3033.             Copyright (c) 1989         Page 5 - 25          Motorola, Inc.
  3034.  
  3035.  
  3036.  
  3037.  
  3038.  
  3039.  
  3040.                   MCX11 - MicroController eXecutive for the 68HC11
  3041.  
  3042.  
  3043.  
  3044.             5.15  .wait.  -  WAIT ON SEMAPHORE
  3045.             
  3046.             CLASS
  3047.             
  3048.                  Semaphore
  3049.             
  3050.             SYNOPSIS
  3051.             
  3052.                  .wait. (SEMA)       [1]
  3053.             
  3054.             DESCRIPTION
  3055.             
  3056.                  The wait  directive is a fundamental function in MCX11.
  3057.                  It is used to make a task wait for a specified event to
  3058.                  occur.   The event  must be  associated with  the given
  3059.                  semaphore.   If the  semaphore is  found  to  be  in  a
  3060.                  PENDing state,  the task  is placed  into an Event Wait
  3061.                  state and  the semaphore is changed to WAITing, and the
  3062.                  context of the current task is saved.  If the semaphore
  3063.                  is in a DONE state, no wait occurs and the task resumes
  3064.                  immediately.   Upon task resumption, the wait directive
  3065.                  returns  the   semaphore  number  of  the  event  which
  3066.                  occurred.
  3067.             
  3068.             CALLING SEQUENCE
  3069.             
  3070.                  ACCB = Semaphore number
  3071.                  swi
  3072.                   FCB .wait.
  3073.                  return
  3074.             
  3075.             RETURN VALUE
  3076.             
  3077.                  None. Registers unchanged.
  3078.             
  3079.             EXAMPLE
  3080.             
  3081.                  The current task wants to wait on a timer semaphore set
  3082.                  up by  a previous  .timer. request.  The semaphore is a
  3083.                  named semaphore, TIMEOUT. The procedure would appear as
  3084.                  follows:
  3085.                  
  3086.                  TIMEOUT   equ   3             Semaphore #3
  3087.                            .
  3088.                            :
  3089.                            ldab  #TIMEOUT      ACCB = semaphore # 3
  3090.                            swi
  3091.                             FCB  .wait.
  3092.                            .                   Point of continuation
  3093.                  
  3094.                  The current  task is put into a WAIT state on semaphore
  3095.                  TIMEOUT as  a result of this request. It will remain in
  3096.  
  3097.  
  3098.  
  3099.             Copyright (c) 1989         Page 5 - 26          Motorola, Inc.
  3100.  
  3101.  
  3102.  
  3103.  
  3104.  
  3105.  
  3106.                   MCX11 - MicroController eXecutive for the 68HC11
  3107.  
  3108.  
  3109.  
  3110.                  this state  until another task, in this case, the clock
  3111.                  driver, signals  TIMEOUT  that  the  timer  period  has
  3112.                  elapsed.  The   task  would   then  continue   at   the
  3113.                  instruction following the FCB.
  3114.             
  3115.             SEE ALSO
  3116.             
  3117.                  .pend., .signal.
  3118.  
  3119.  
  3120.  
  3121.  
  3122.  
  3123.  
  3124.  
  3125.  
  3126.  
  3127.  
  3128.  
  3129.  
  3130.  
  3131.  
  3132.  
  3133.  
  3134.  
  3135.  
  3136.  
  3137.  
  3138.  
  3139.  
  3140.  
  3141.  
  3142.  
  3143.  
  3144.  
  3145.  
  3146.  
  3147.  
  3148.  
  3149.  
  3150.  
  3151.  
  3152.  
  3153.  
  3154.  
  3155.  
  3156.  
  3157.  
  3158.  
  3159.  
  3160.  
  3161.  
  3162.  
  3163.  
  3164.  
  3165.             Copyright (c) 1989         Page 5 - 27          Motorola, Inc.
  3166.  
  3167.  
  3168.  
  3169.  
  3170.  
  3171.  
  3172.                  MCX11 - MicroController eXecutive for the MC68HC11
  3173.  
  3174.  
  3175.  
  3176.                                      SECTION 6
  3177.                                           
  3178.                                 SYSTEM CONFIGURATION
  3179.                                           
  3180.             
  3181.             6.1  SYSTEM CONFIGURATION CONCEPTS
  3182.             
  3183.             Another configuration  concept central  to the  operation of
  3184.             MCX11 is  that of  pre-definition.   Most real  time systems
  3185.             used  in   embedded  operations   have   a   fairly   static
  3186.             configuration.   That is to say, the equipment configuration
  3187.             is not  subject to  frequent changes nor is the basic system
  3188.             functionality.  Consequently, the system designer can define
  3189.             the operating  environment  so  that  the  operating  system
  3190.             dynamics are  avoided to  the greatest  degree possible.  In
  3191.             other words,  the number of tasks concurrently executing may
  3192.             change but  the relative  priorities of  tasks remain fixed.
  3193.             Thus task  priorities can  be pre-assigned.   The  amount of
  3194.             free memory  can be  computed  and  established,  number  of
  3195.             queues and  their  sizes,  and  the  number  of  timers  and
  3196.             semaphores are  all defined prior to runtime.  The result is
  3197.             that MCX11  works in an established environment which yields
  3198.             the effect   of  less system  overhead,  smaller  code,  and
  3199.             faster execution;  all three being  desirable in a real time
  3200.             system.
  3201.             
  3202.             In order  to define  a  MCX11  system  configuration  it  is
  3203.             necessary to  configure those  data and  control  structures
  3204.             with  the   application  specific  information  which  MCX11
  3205.             requires. The  configuration is done by creating AS11 source
  3206.             code files  which define the necessary information needed to
  3207.             assemble with  MCX11 source  code  to  define  a  particular
  3208.             configuration.  The   following  paragraphs   describe   the
  3209.             techniques.
  3210.             
  3211.             
  3212.             6.2  MCX11 SYSTEM TABLE MEMORY REQUIREMENTS
  3213.             
  3214.             MCX11 system  tables must  necessarily reside  in an area of
  3215.             RAM.  This section is included to assist the system designer
  3216.             in determining  the amount of ROM and RAM required for MCX11
  3217.             tables. The  amount of  RAM and ROM may be computed from the
  3218.             equations below  given the  following  system  configuration
  3219.             information:
  3220.             
  3221.                  NTASKS    The number of tasks
  3222.                  NNAMSEM   The number of named semaphores
  3223.                  NQUEUES   The number of queues
  3224.                  NTIMERS   The number of timers
  3225.             
  3226.  
  3227.  
  3228.  
  3229.  
  3230.  
  3231.             Copyright (c) 1989         Page 6 - 1          Motorola, Inc.
  3232.  
  3233.  
  3234.  
  3235.  
  3236.  
  3237.  
  3238.                  MCX11 - MicroController eXecutive for the MC68HC11
  3239.  
  3240.  
  3241.  
  3242.             The symbols above are used by MCX11 and should be considered
  3243.             reserved symbols.  These numbers  are obviously exclusive of
  3244.             any RAM and ROM requirements of the application tasks.
  3245.             
  3246.             Tasks
  3247.             
  3248.                  A Task  Control Block  occupies 5  bytes of  RAM and  7
  3249.                  bytes of ROM.
  3250.                  
  3251.                       TASK bytes (RAM) = NTASKS * 5 + 5
  3252.                       TASK bytes (ROM) = NTASKS * 7
  3253.             
  3254.             Semaphores
  3255.             
  3256.                  Each semaphore  requires 1  byte of  RAM.  Total system
  3257.                  area required  for semaphore  control is  the number of
  3258.                  named semaphores  + the  number of  tasks + 2 times the
  3259.                  number of queues.
  3260.                  
  3261.                       SEMA bytes (RAM) = NNAMSEM + NTASKS + 2 * NQUEUES
  3262.             
  3263.             
  3264.             Queues
  3265.             
  3266.                  Each queue  consists of  a queue  header and  the queue
  3267.                  body.   Each queue header requires 3 bytes of RAM and 6
  3268.                  bytes of ROM.  Each defined queue body requires an area
  3269.                  of RAM  defined by the product of its Width (W) and its
  3270.                  Depth (D).
  3271.                  
  3272.                       QUEUE bytes (RAM) = NQUEUES * 3 + Sum(Wi * Di),
  3273.                                           where Wi is the width and Di
  3274.                                           is the depth of the ith queue,
  3275.                                           and i ranges from 1 - NQUEUES.
  3276.                  
  3277.                       QUEUE bytes (ROM) = NQUEUES * 6
  3278.             
  3279.             
  3280.             Clock
  3281.             
  3282.                  Timers require  8 bytes  of RAM  each.   The total area
  3283.                  required for  timer control  and storage is the product
  3284.                  of 8 and the number of defined timers.
  3285.                  
  3286.                       TIMER bytes (RAM) = NTIMERS * 8
  3287.             
  3288.  
  3289.  
  3290.  
  3291.  
  3292.  
  3293.  
  3294.  
  3295.  
  3296.  
  3297.             Copyright (c) 1989         Page 6 - 2          Motorola, Inc.
  3298.  
  3299.  
  3300.  
  3301.  
  3302.  
  3303.  
  3304.                  MCX11 - MicroController eXecutive for the MC68HC11
  3305.  
  3306.  
  3307.  
  3308.                                      SECTION 7
  3309.                                           
  3310.                              DEVICE DRIVER & INTERRUPTS
  3311.                                           
  3312.             
  3313.             7.1  DRIVER CONCEPTS
  3314.             
  3315.             Device  drivers   are  program   modules  which  provide  an
  3316.             organized software  interface between  a physical device and
  3317.             the application programs using the device.  The intent is to
  3318.             mask the  specifics of  the device's  hardware peculiarities
  3319.             from the application software.  By doing so, the application
  3320.             code need  only conform  to the  protocol which  the  device
  3321.             driver expects  in order to perform a function.  Each device
  3322.             driver may  have a  protocol unique to its function, i.e., a
  3323.             disk driver  has different  functional requirements  from an
  3324.             analog-to-digital converter.
  3325.             
  3326.             In order  to accommodate the wide range of devices which are
  3327.             found in  real-time systems, the device drivers in MCX11 are
  3328.             structured as  tasks.   As a  task, a  device driver has the
  3329.             most flexible  environment with  complete access  to  system
  3330.             resources via  the Executive  Service Requests.  Actually, a
  3331.             device driver  usually consists  of two  parts:   the driver
  3332.             task, and  the interrupt  service routine (ISR).  The latter
  3333.             is used when the device can cause an interrupt to signal the
  3334.             completion of a function or the availability of the device.
  3335.             
  3336.             An ISR  exists to  handle an exception in the normal flow of
  3337.             processing.   The general  philosophy of MCX11 drivers is to
  3338.             minimize the time spent in the interrupt service routine and
  3339.             let the  task portion  handle the  real work  of the driver.
  3340.             This design  concept places  no restrictions on the designer
  3341.             for either  the ISR or the task functionality. The structure
  3342.             of the  ISR is  explained more  completely in  the following
  3343.             section.
  3344.             
  3345.             
  3346.             7.2  INTERRUPT SERVICE
  3347.             
  3348.             The  classic   interrupt   processing   philosophy   is   to
  3349.             acknowledge the  interrupt and  save the  current  processor
  3350.             context.   Then a branch is made to a software routine where
  3351.             the code  services the  specific interrupt  and performs any
  3352.             required operations.  When the  interrupt service routine is
  3353.             complete, control  of the  main program  is resumed  at  the
  3354.             point of  interruption.   MCX11 uses  a modified  version of
  3355.             that sequence.
  3356.             
  3357.             The  MC68HC11  microcontroller  always  pushes  the  current
  3358.             processor context of nine (9) bytes on the active stack when
  3359.             an interrupt  occurs. That having been done, it acknowledges
  3360.  
  3361.  
  3362.  
  3363.             Copyright (c) 1989         Page 7 - 1          Motorola, Inc.
  3364.  
  3365.  
  3366.  
  3367.  
  3368.  
  3369.  
  3370.                  MCX11 - MicroController eXecutive for the MC68HC11
  3371.  
  3372.  
  3373.  
  3374.             the interrupt  and vectors automatically to the specific ISR
  3375.             written for  that event.  The user must initialize each two-
  3376.             byte interrupt  vector location  specific to his application
  3377.             as part of the initialization code.
  3378.             
  3379.             MCX11  presets   the  vector  locations  for  the  following
  3380.             interrupts. All  others not  specifically  reserved  by  the
  3381.             MC68HC11 are available to the user.
  3382.             
  3383.                     Event               Address
  3384.                  
  3385.                  Clock (RTI)          $FFF0-$FFF1
  3386.                  MCX11 ESR request    $FFF6-$FFF7
  3387.                  Power On/Reset       $FFFE-$FFFF
  3388.             
  3389.             MCX11 uses a modified version of the classical ISR approach.
  3390.             The sequence is the same until the return to the interrupted
  3391.             program is  made at  the  end  of  the  ISR.  In  MCX11,  an
  3392.             interrupt may  be the  event for which a task is waiting. If
  3393.             so, a  notification of  the event's occurrence must be given
  3394.             to the  task. But  the possibility  exists that  the waiting
  3395.             task has  a  higher  priority  than  the  interrupted  task.
  3396.             Notification of  the event should remove the wait state from
  3397.             the higher  priority task  thus making it runnable, assuming
  3398.             it is not otherwise blocked.
  3399.             
  3400.             At that  point, a  decision has  to be  made as  to  how  to
  3401.             continue. Whichever  task is  of higher  priority,  the  one
  3402.             interrupted or the one which was waiting, it will be the one
  3403.             to resume  processing. If  it is  the interrupted  task,  it
  3404.             resumes at  the point  of interruption  as  in  the  classic
  3405.             sequence. If  the latter  task  is  of  higher  priority,  a
  3406.             context switch  is performed in which it is made the current
  3407.             task. Its  processor context  is restored from its stack and
  3408.             the task  resumes at  the location  following the  ESR which
  3409.             caused it to wait. The interrupted task remains runnable and
  3410.             will continue at the point of its interruption at some later
  3411.             time when it becomes the highest priority runnable task.
  3412.             
  3413.             MCX11 provides  a common  exit routine  to  which  all  ISRs
  3414.             should branch  if there  is the  possibility  of  a  context
  3415.             switch as  the  result  of  the  interrupt.  The  function's
  3416.             primary responsibility is to signal a specified semaphore of
  3417.             the occurrence  of an  event and  to dispatch control to the
  3418.             highest priority  task which is runnable after the interrupt
  3419.             has been serviced.
  3420.             
  3421.             
  3422.             7.2.1 Interrupt Processing Variables
  3423.             
  3424.             In order  for MCX11 interrupt servicing to operate properly,
  3425.             it is  necessary to  observe a  few rules of the road. There
  3426.  
  3427.  
  3428.  
  3429.             Copyright (c) 1989         Page 7 - 2          Motorola, Inc.
  3430.  
  3431.  
  3432.  
  3433.  
  3434.  
  3435.  
  3436.                  MCX11 - MicroController eXecutive for the MC68HC11
  3437.  
  3438.  
  3439.  
  3440.             are some  system variables  which are  used during interrupt
  3441.             processing in  the ISR  and in  the common ISR exit routine.
  3442.             These variables  must be used only in the ISR and should not
  3443.             be used  elsewhere. A  listing of  the variables and a brief
  3444.             description of  them follows. Their addresses are also given
  3445.             as a  displacement from the base address of the MCX11 system
  3446.             variables, MCXVAR.  MCXVAR may be located at any RAM address
  3447.             but must  be predefined  and assembled with the MCX11 kernel
  3448.             code.
  3449.             
  3450.             intlvl   (address MCXVAR+11)
  3451.             
  3452.                  This byte  variable is  a  counter  of  the  number  of
  3453.                  interrupts stacked  but not  yet processed  completely.
  3454.                  When an  interrupt occurs in a task, intlvl will always
  3455.                  contain a value of zero. The ISR code must increment it
  3456.                  by 1  to indicate  that an ISR is in process. If a task
  3457.                  calls the  MCX11 kernel,  intlvl is  incremented  to  a
  3458.                  value of 1. If an interrupt were to occur while control
  3459.                  is in  the MCX11 kernel, intlvl would be incremented to
  3460.                  2 by the ISR, etc.
  3461.                  
  3462.                  MCX11  allows  the  existence  of  interruptible  ISRs;
  3463.                  therefore, intlvl can assume any value up to the number
  3464.                  of possible interrupts in the system. As interrupts are
  3465.                  processed by  the common  ISR  exit  logic,  intlvl  is
  3466.                  decremented. A  resumption of  processing at  the  task
  3467.                  level can  only occur  when the  decremented  value  of
  3468.                  intlvl becomes  zero.  Otherwise,  the  non-zero  value
  3469.                  indicates the  existence of an interrupt which has been
  3470.                  incompletely serviced.  In that  case, the  common  ISR
  3471.                  exit logic  returns control  to the interrupted ISR and
  3472.                  resumes  processing   at  that   point.  Thus,   nested
  3473.                  interrupts and  re-entrant ISRs  are  handled  cleanly,
  3474.                  quickly, and automatically by MCX11.
  3475.                  
  3476.             curtsk  (address MCXVAR+5)
  3477.                  
  3478.                  This byte  variable contains  the number of the current
  3479.                  task. It  is to be considered a READ-ONLY variable. The
  3480.                  user should  NEVER write to this variable. It is needed
  3481.                  during  ISR   processing  to  determine  if  the  MCX11
  3482.                  Dispatcher was interrupted.
  3483.                  
  3484.             curtcb  (address MCXVAR+6)
  3485.                  
  3486.                  This  2-byte  variable  contains  the  address  of  the
  3487.                  current  task's  Task  Control  Block  (TCB).  The  TCB
  3488.                  contains an  entry for  the task's stack pointer. MCX11
  3489.                  interrupt  processing   requires  that  the  ISR  which
  3490.                  increments intlvl  to a  value of  1 must also save the
  3491.  
  3492.  
  3493.  
  3494.  
  3495.             Copyright (c) 1989         Page 7 - 3          Motorola, Inc.
  3496.  
  3497.  
  3498.  
  3499.  
  3500.  
  3501.  
  3502.                  MCX11 - MicroController eXecutive for the MC68HC11
  3503.  
  3504.  
  3505.  
  3506.                  current task's  stack pointer in its TCB. The variable,
  3507.                  curtcb, is READ-ONLY.
  3508.             
  3509.             
  3510.             7.2.2 Interrupt Processing Code
  3511.             
  3512.             All ISRs  which have  the capability  of causing  a  context
  3513.             switch should  incorporate the  following routine as in-line
  3514.             code in  the ISR.  If the  ISR is  to be  allowed to  enable
  3515.             interrupts, this code should precede the CLI instruction. As
  3516.             a rule  it should  occur early  in the  ISR  but  there  are
  3517.             exceptions. (Refer  to the  MCX11 clock  driver's ISR, whose
  3518.             entry address  has the  symbol rtiisr, for a good example of
  3519.             an exception to the rule.)
  3520.             
  3521.             Note that the label, notlvl0, used in the code segment below
  3522.             will need  to be changed for each ISR. The symbols ACTSP and
  3523.             SYSTACK are  not variables  and should not be changed. ACTSP
  3524.             is equated to the value of 1 and represents the displacement
  3525.             into the  TCB where  the task's  stack  pointer  is  stored.
  3526.             SYSTACK is the location of the base of the System Stack area
  3527.             and is defined in the System Configuration source code file,
  3528.             SYSTEM.AS.
  3529.             
  3530.             
  3531.                            tst   intlvl    Test for task level interrupt
  3532.                            bne   notlvl0   Branch if not task level int
  3533.                            tst   curtsk    See if Dispatcher interrupted
  3534.                            beq   notlvl0   Branch if so
  3535.                            ldx   curtcb    Get task's TCB address
  3536.                            sts   ACTSP,x   Save task's stack pointer
  3537.                            lds   #SYSTACK  Change to System Stack
  3538.                  notlvl0   inc   intlvl    Increment the interrupt level
  3539.                  
  3540.                  After this  point, the  CLI instruction may be inserted
  3541.                  if desired.
  3542.             
  3543.             
  3544.             The interrupt  service code  follows. An important factor in
  3545.             interrupt  processing  throughput  is  the  length  of  time
  3546.             interrupts are  disabled during  the  ISR.    In  all  ISRs,
  3547.             interrupts must  be disabled long enough to perform the code
  3548.             segment above and only then should interrupts be re-enabled.
  3549.             Ideally,  interrupt   routines  should   be  performed  with
  3550.             interrupts enabled to allow other interrupts to be serviced.
  3551.             
  3552.             The exit  from the  ISR routine is via a branch to the MCX11
  3553.             common Interrupt Service Routine Exit routine located at the
  3554.             address having  the symbol,  isrrtn. This routine allows for
  3555.             optionally signalling  a semaphore  during the exit process.
  3556.             The ISR  may wish  to signal  a  semaphore  that  the  event
  3557.             associated with  the interrupt  has occurred.  To do so, the
  3558.  
  3559.  
  3560.  
  3561.             Copyright (c) 1989         Page 7 - 4          Motorola, Inc.
  3562.  
  3563.  
  3564.  
  3565.  
  3566.  
  3567.  
  3568.                  MCX11 - MicroController eXecutive for the MC68HC11
  3569.  
  3570.  
  3571.  
  3572.             ISR simply  puts the number of the semaphore to be signalled
  3573.             into the  B-Accumulator and the executes a branch to isrrtn.
  3574.             From there  on, the  further processing  of the interrupt is
  3575.             performed automatically  by MCX11. As an example, assume the
  3576.             ISR wants  to signal a semaphore and that the label used for
  3577.             the semaphore  is EVNTSEMA. Then the concluding code segment
  3578.             in the ISR is
  3579.             
  3580.             
  3581.                            ldab  #EVNTSEMA   Load ACCB with semaphore #
  3582.                            jmp   isrrtn      Jump to exit logic.
  3583.             
  3584.             
  3585.             If no  semaphore is to be signalled during the exit routine,
  3586.             the ISR  should make  sure that the B-Accumulator is cleared
  3587.             before branching to isrrtn.
  3588.  
  3589.  
  3590.  
  3591.  
  3592.  
  3593.  
  3594.  
  3595.  
  3596.  
  3597.  
  3598.  
  3599.  
  3600.  
  3601.  
  3602.  
  3603.  
  3604.  
  3605.  
  3606.  
  3607.  
  3608.  
  3609.  
  3610.  
  3611.  
  3612.  
  3613.  
  3614.  
  3615.  
  3616.  
  3617.  
  3618.  
  3619.  
  3620.  
  3621.  
  3622.  
  3623.  
  3624.  
  3625.  
  3626.  
  3627.             Copyright (c) 1989         Page 7 - 5          Motorola, Inc.
  3628.  
  3629.  
  3630.  
  3631.  
  3632.  
  3633.  
  3634.                  MCX11 - MicroController eXecutive for the MC68HC11
  3635.  
  3636.  
  3637.  
  3638.                                      SECTION 8
  3639.                                           
  3640.                                   ADVANCED TOPICS
  3641.                                           
  3642.             
  3643.             8.1  OTHER TOPICS
  3644.             
  3645.             Other topics  of interest  will be  added to this section as
  3646.             they are researched and documented.
  3647.  
  3648.  
  3649.  
  3650.  
  3651.  
  3652.  
  3653.  
  3654.  
  3655.  
  3656.  
  3657.  
  3658.  
  3659.  
  3660.  
  3661.  
  3662.  
  3663.  
  3664.  
  3665.  
  3666.  
  3667.  
  3668.  
  3669.  
  3670.  
  3671.  
  3672.  
  3673.  
  3674.  
  3675.  
  3676.  
  3677.  
  3678.  
  3679.  
  3680.  
  3681.  
  3682.  
  3683.  
  3684.  
  3685.  
  3686.  
  3687.  
  3688.  
  3689.  
  3690.  
  3691.  
  3692.  
  3693.             Copyright (c) 1989         Page 8 - 1          Motorola, Inc.
  3694.  
  3695.  
  3696.  
  3697.  
  3698.  
  3699.  
  3700.                  MCX11 - MicroController eXecutive for the MC68HC11
  3701.  
  3702.  
  3703.  
  3704.                                      APPENDIX A
  3705.                                           
  3706.                            MCX11 DISTRIBUTED SOURCE FILES
  3707.                                           
  3708.             
  3709.             MCX11 is  distributed as  a collection of files. Those files
  3710.             and their purposes are briefly described below.
  3711.             
  3712.             CLKDRVR.AS
  3713.             
  3714.             The AS11  source code  of  the  RTI  clock  driver  and  RTI
  3715.             Interrupt Service Routine.
  3716.             
  3717.             ESREQU.AS
  3718.             
  3719.             These are  just the  equates for  MCX11  ESRs  included  for
  3720.             completeness.
  3721.             
  3722.             MCX.AS
  3723.             
  3724.             This is the AS11 source code of the MCX11 kernel. Unless you
  3725.             are expanding  the functions  of  the  kernel  or  fixing  a
  3726.             reported bug, this file probably won't change too much.
  3727.             
  3728.             SYSTEM.AS
  3729.             
  3730.             This AS11 source code file contains the application specific
  3731.             information and  should be  studied very  closely.  It  also
  3732.             contains initialization  code  which  may  be  necessary  to
  3733.             change to meet the needs of a given application. The file is
  3734.             pre-configured  with   the  specifications  needed  for  the
  3735.             demonstration programs in file TEST.AS.
  3736.             
  3737.             TEST.AS
  3738.             
  3739.             This is  an AS11  source code  file containing 4 tasks which
  3740.             demonstrate the  use of all of the MCX11 ESRs. It doesn't do
  3741.             anything practical except to give the user a limited look at
  3742.             how to accomplish certain operations.
  3743.             
  3744.             VECTORS.AS
  3745.             
  3746.             AS11 source  code containing  all of  the  vectors  used  by
  3747.             MCX11.  This  file  may  need  to  be  edited  for  a  given
  3748.             application.
  3749.             
  3750.             ASSEMBLE.BAT
  3751.             
  3752.             A MS-DOS  Batch file  used to  assemble MCX11  and the  TEST
  3753.             programs. It also produces a listing file.
  3754.             
  3755.             MANUAL.DOC
  3756.  
  3757.  
  3758.  
  3759.             Copyright (c) 1989         Page A - 1          Motorola, Inc.
  3760.  
  3761.  
  3762.  
  3763.  
  3764.  
  3765.  
  3766.                  MCX11 - MicroController eXecutive for the MC68HC11
  3767.  
  3768.  
  3769.  
  3770.             
  3771.             The MCX11 User's Manual is contained in this file. It can be
  3772.             printed out directly to any ASCII compatible printer.
  3773.             
  3774.             README.DOC
  3775.             
  3776.             Some notes about getting started with MCX11.
  3777.             
  3778.  
  3779.  
  3780.  
  3781.  
  3782.  
  3783.  
  3784.  
  3785.  
  3786.  
  3787.  
  3788.  
  3789.  
  3790.  
  3791.  
  3792.  
  3793.  
  3794.  
  3795.  
  3796.  
  3797.  
  3798.  
  3799.  
  3800.  
  3801.  
  3802.  
  3803.  
  3804.  
  3805.  
  3806.  
  3807.  
  3808.  
  3809.  
  3810.  
  3811.  
  3812.  
  3813.  
  3814.  
  3815.  
  3816.  
  3817.  
  3818.  
  3819.  
  3820.  
  3821.  
  3822.  
  3823.  
  3824.  
  3825.             Copyright (c) 1989         Page A - 2          Motorola, Inc.
  3826.  
  3827.  
  3828.  
  3829.